Skip to content

Instantly share code, notes, and snippets.

@brennandunn
Created August 27, 2008 15:50
Show Gist options
  • Save brennandunn/7512 to your computer and use it in GitHub Desktop.
Save brennandunn/7512 to your computer and use it in GitHub Desktop.
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