Created
April 29, 2012 00:44
-
-
Save ryanlecompte/2522927 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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