def initialize(name="oSthinggg", age=21) @name = name @age = age end
def is_admin? if to_s == "true" "a admin,good!give your fake flag! flag{RuBy3rB_1$_s3_1Z}" else "not admin,your "+@to_s end end
def age if @age > 20 "old" else "young" end end
def merge(original, additional, current_obj = original) additional.each do |key, value| if value.is_a?(Hash) next_obj = current_obj.respond_to?(key) ? current_obj.public_send(key) : Object.new current_obj.singleton_class.attr_accessor(key) unless current_obj.respond_to?(key) current_obj.instance_variable_set("@#{key}", next_obj) merge(original, value, next_obj) else current_obj.singleton_class.attr_accessor(key) unless current_obj.respond_to?(key) current_obj.instance_variable_set("@#{key}", value) end end original end end
user = User.new("oSthinggg", 21)
get "/" do redirect "/set_age" end
get "/set_age" do ERB.new(File.read("views/age.erb", encoding: "UTF-8")).result(binding) end
post "/set_age" do request.body.rewind age = JSON.parse(request.body.read) user.merge(user,age) end
get "/view" do name=user.name().to_s op_age=user.age().to_s is_admin=user.is_admin?().to_s ERB::new("<h1>Hello,oSthinggg!#{op_age} man!you #{is_admin} </h1>").result end