Yes, it is called method_missing ; it is called whenever the undefined method is used. You can use it to add or emulate any method you want, including accessors.
For example, if you selected this on Hash , you can treat the contents of the hash as properties:
h = {} def h.method_missing(*args) if args.length == 1 self[args[0]] elsif args.length == 2 and args[0].to_s =~ /^(.*)=$/ self[$1.intern] = args[1] else super end end
let you write:
h.bob = "Robert"
and
if h.bill == "William" ...
etc. in addition to the more normal style h[:bob] = ...
source share