Created
August 30, 2010 22:26
-
-
Save foca/558149 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
module Numbers | |
def foo | |
2 | |
end | |
def bar | |
foo * 2 | |
end | |
end | |
class Something | |
mix Numbers, :foo => :numeric_foo | |
def foo | |
"foo" | |
end | |
end | |
# So now… | |
Something.new.bar #=> 4 | |
# Or | |
Something.new.bar #=> "foofoo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code executes from top to bottom. The
mix
happens beforefoo
is defined. Themix
call will error if it is mixing in a method that already exists, but in your example thefoo
method doesn't exist yet. I think you would only need to setfoo
tonil
if it was like this:Just my understanding so far. I could very well be wrong.