Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
excessively dynamic accessors
class MyConfiguration < BasicObject
def method_missing name, *args
getter = name.end_with?(?=) ? name[0..-2] : name
(class << self; self end).class_eval { attr_accessor getter }
__send__ name, *args
config =
config.liverpool = 4
# [4, nil]
puts [config.liverpool,].inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment