I came across this code while trying to learn about creating your own method_missing method, and I don't understand it. What I don't understand are these parts: method_sym[-1] == "=" and method_sym[0..-2] What do they refer to? I tried some simulations in irb, but this just returned some weird stuff.
Could anyone break it down for me? I would really appreciate it. Thanks!
class UberHash
def method_missing(method_sym, *args, &block)
if method_sym[-1] == "="
instance_variable_set("@#{method_sym[0..-2]}", args[0])
else
instance_variable_get("@#{method_sym}")
end
end
end