Skip to content

Instantly share code, notes, and snippets.

@ryanlecompte
Created April 29, 2012 00:44
Show Gist options
  • Save ryanlecompte/2522927 to your computer and use it in GitHub Desktop.
Save ryanlecompte/2522927 to your computer and use it in GitHub Desktop.
class Foo
def foo; "foo" end
def bar; "bar" end
def baz; "baz" end
end
class Bar < Foo
attr_accessor :plural
def self.wrap(*methods)
methods.each do |method|
define_method(method) do
plural ? "the #{super()}s" : "a #{super()}"
end
end
end
wrap :foo, :bar, :baz
end
bar = Bar.new
puts bar.foo
puts bar.baz
bar.plural = true
puts bar.bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment