Skip to content

Instantly share code, notes, and snippets.

@joallard
Last active July 26, 2018 17:48
Show Gist options
  • Save joallard/4893ed859116f1a81761ffc440db64e9 to your computer and use it in GitHub Desktop.
Save joallard/4893ed859116f1a81761ffc440db64e9 to your computer and use it in GitHub Desktop.
Does a bare call to super take into account modified arguments? Also see: https://stackoverflow.com/questions/27981314/calling-super-without-arguments
class A
def foo(**opts)
opts.merge(a: true)
end
end
class B < A
def foo(**opts)
opts[:b] = true
super
end
end
class C < A
def foo(**opts)
opts = {completely: :different}
opts[:c] = true
super
end
end
puts B.new.foo(original: 1) # {:original=>1, :b=>true, :a=>true}
puts C.new.foo(original: 1) # {:completely=>:different, :c=>true, :a=>true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment