Skip to content

Instantly share code, notes, and snippets.

@georgebonnr
Last active May 6, 2019 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgebonnr/5914904 to your computer and use it in GitHub Desktop.
Save georgebonnr/5914904 to your computer and use it in GitHub Desktop.
Ruby errors
# Ruby-doc documentation from http://ruby-doc.org/core-2.0/Object.html#method-i-class
guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
# ------------------------------------------------------------------------------
# Here is what I get on my machine:
guy = "Bob"
# ==> "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
# =NoMethodError: undefined method `define_singleton_method' for "Bob":String
# = from (irb):71
guy.hello
# =NoMethodError: undefined method `hello' for "Bob":String
# = from (irb):72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment