Created
August 27, 2008 15:50
-
-
Save brennandunn/7512 to your computer and use it in GitHub Desktop.
This file contains 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 James | |
def movie ; "The Big Lebowski #{@special}" ; end | |
end | |
module Bob | |
def movie ; "Spiderman #{@special}" ; end | |
end | |
module Jane | |
def movie ; "Raiders of the Lost Ark #{@special}" ; end | |
end | |
class Friends | |
include James | |
include Bob | |
def initialize(something_special = nil) | |
@special = something_special | |
end | |
end | |
f = Friends.new('is my favorite movie') | |
f.movie # => "Spiderman is my favorite movie" | |
Friends.send :include, Jane | |
f.movie # => "Raiders of the Lost Ark is my favorite movie" | |
# The problem is our 'Friends' group is a rather homogenous bunch. How can we single out a movie from | |
# this friends group? | |
james_favorite = James.instance_method(:movie) # => #<UnboundMethod: James#movie> | |
james_favorite.bind(Friends.new('sucks')).call # => "The Big Lebowski sucks" | |
james_favorite.bind(f).call # => "The Big Lebowski is my favorite movie" | |
f.movie # => "Raiders of the Lost Ark is my favorite movie" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment