Skip to content

Instantly share code, notes, and snippets.

@fletcherm
Created November 29, 2009 16:59
Show Gist options
  • Save fletcherm/244979 to your computer and use it in GitHub Desktop.
Save fletcherm/244979 to your computer and use it in GitHub Desktop.
def append(object)
object << "hello"
end
a = [ 1 ] # array
b = "yo ho ho" # string
c = StringIO.new("yo ho ho") # string IO; still responds to the << method
d = { "hi" => "there" } # hash; does not respond to << method
append a # works
append b # works
append c # works
append d # blows up since there is no << method on hashes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment