Last active
July 21, 2017 02:42
-
-
Save nekonenene/314634d8fdb5ee386378067f430ed984 to your computer and use it in GitHub Desktop.
refine / using で安全にオブジェクトへメソッド追加
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module StringExtend | |
refine String do | |
def reverse | |
"aaa" | |
end | |
end | |
end | |
module TestModule | |
def output_from_module | |
puts "my_string".reverse | |
end | |
end | |
class TestClass | |
using StringExtend | |
include TestModule | |
def output_from_class | |
puts "my_string".reverse | |
end | |
end | |
test = TestClass.new | |
test.output_from_module # Output: gnirts_ym | |
test.output_from_class # Output: aaa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment