Skip to content

Instantly share code, notes, and snippets.

@inopinatus
Last active October 5, 2020 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inopinatus/8a0e2fcae015b985ef928b9c67d47938 to your computer and use it in GitHub Desktop.
Save inopinatus/8a0e2fcae015b985ef928b9c67d47938 to your computer and use it in GitHub Desktop.
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
end
end
config = MyConfiguration.new
config.liverpool = 4
# [4, nil]
puts [config.liverpool, config.barcelona].inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment