Skip to content

Instantly share code, notes, and snippets.

@faoiseamh
Created May 13, 2015 19:19
Show Gist options
  • Save faoiseamh/08fab11a2dfb7ace4192 to your computer and use it in GitHub Desktop.
Save faoiseamh/08fab11a2dfb7ace4192 to your computer and use it in GitHub Desktop.
Ruby keyword arguments wtf
class Demo1
def initialize a:, b:
@a = a
@b = b
puts "@a = #{@a.inspect} and @b = #{@b.inspect}"
end
end
Demo1.new a: 'one', b: 'two'
# ==> @a = nil and @b = "two"
class Demo2
def initialize a:, b:
@wtf = 'asdfa'
@a = a
@b = b
puts "@a = #{@a.inspect} and @b = #{@b.inspect}"
end
end
Demo2.new a: 'one', b: 'two'
# ==> @a = "one" and @b = "two"
class Demo3
def initialize a, b
@a = a
@b = b
puts "@a = #{@a.inspect} and @b = #{@b.inspect}"
end
end
Demo3.new 'one', 'two'
# ==> @a = "one" and @b = "two"
@faoiseamh
Copy link
Author

This was an issue in Ruby 2.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment