Skip to content

Instantly share code, notes, and snippets.

@zverok
Created November 22, 2016 15:24
Show Gist options
  • Save zverok/ae70b0ee0f58ff0e7939d807b60aebd2 to your computer and use it in GitHub Desktop.
Save zverok/ae70b0ee0f58ff0e7939d807b60aebd2 to your computer and use it in GitHub Desktop.
module Refinements
refine Object do
def derp
yield self
end
end
end
module A
using Refinements
def self.foo
'test'.derp { |s| '(' + s + ')' }
end
end
p A.foo
# jruby 9.1.6.0 (2.3.1) 2016-11-22 0150a76 OpenJDK Server VM 24.65-b04 on 1.7.0_65-b32 +jit [linux-i386]
# NoMethodError: undefined method `derp' for "test":String
# foo at tmp/ref.rb:13
# <main> at tmp/ref.rb:17
#
# ruby 2.3.1
# => "(test)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment