Skip to content

Instantly share code, notes, and snippets.

@hgmnz
Created November 28, 2010 18:34
Show Gist options
  • Save hgmnz/719171 to your computer and use it in GitHub Desktop.
Save hgmnz/719171 to your computer and use it in GitHub Desktop.
Object#method
ree-1.8.7-2010.02 > some_string = "hi there"
=> "hi there"
ree-1.8.7-2010.02 > some_string.capitalize
=> "Hi there"
ree-1.8.7-2010.02 > some_method = some_string.method :capitalize
=> #<Method: String#capitalize>
ree-1.8.7-2010.02 > some_method.call
=> "Hi there"
ree-1.8.7-2010.02 > String.class_eval { remove_method(:capitalize) }
=> String
ree-1.8.7-2010.02 > some_string.capitalize
NoMethodError: undefined method `capitalize' for "hi there":String
from (irb):18
ree-1.8.7-2010.02 > some_method.call
=> "Hi there"
ree-1.8.7-2010.02 > unbound = some_method.unbind
=> #<UnboundMethod: String#capitalize>
ree-1.8.7-2010.02 > unbound.call
NoMethodError: undefined method `call' for #<UnboundMethod: String#capitalize>
from (irb):23
ree-1.8.7-2010.02 > another_string = "bye bye"
=> "bye bye"
ree-1.8.7-2010.02 > another_string.capitalize
NoMethodError: undefined method `capitalize' for "bye bye":String
from (irb):26
ree-1.8.7-2010.02 > rebound = unbound.bind(another_string)
=> #<Method: String#capitalize>
ree-1.8.7-2010.02 > rebound.call
=> "Bye bye"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment