Skip to content

Instantly share code, notes, and snippets.

@ohnishiakira
Created June 15, 2015 05:54
Show Gist options
  • Save ohnishiakira/9c81cf19f6633142557b to your computer and use it in GitHub Desktop.
Save ohnishiakira/9c81cf19f6633142557b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
module StringRefine
refine String do
def refine_test
self.upcase
end
end
end
class Hoge
using StringRefine
def test
p 'hoge'.refine_test
#=> "HOGE"
p %w( hoge fuga ).map{|s| s.refine_test }
#=> ["HOGE", "FUGA"]
p %w( hoge fuga ).map(&:refine_test)
#-> NoMethodError
end
end
puts RUBY_VERSION
#=> 2.2.2
Hoge.new.test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment