Skip to content

Instantly share code, notes, and snippets.

@tyre
Created November 9, 2012 13:46
Show Gist options
  • Save tyre/4045730 to your computer and use it in GitHub Desktop.
Save tyre/4045730 to your computer and use it in GitHub Desktop.
Keyword Arguments + iVars
2.0.0-preview1 :001 > class Walrus
2.0.0-preview1 :002?> attr_accessor :bubbles
2.0.0-preview1 :003?> def initialize(bubbles: @bubbles)
2.0.0-preview1 :004?> end
2.0.0-preview1 :005?> end
=> nil
2.0.0-preview1 :006 > Walrus.new bubbles: 'It works!'
=> #<Walrus:0x007fe8a1e78e48>
2.0.0-preview1 :007 > _.bubbles
=> nil
Maybe it is hiding! (This doesn't make sense why it would be the case, I'm just trying)
2.0.0-preview1 :012 > w = Walrus.new(bubbles: 7)
=> #<Walrus:0x007fe8a1ea93e0>
2.0.0-preview1 :013 > w
=> #<Walrus:0x007fe8a1ea93e0>
2.0.0-preview1 :014 > w.instance_variable_get :@bubbles
=> nil
Walrus, y u no bubbles?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment