Created
January 30, 2014 01:35
-
-
Save pinzolo/8701062 to your computer and use it in GitHub Desktop.
Rangeに存在しないけど、Arrayに存在するメソッドの場合は委譲する
This file contains hidden or 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
# coding: utf-8 | |
class Range | |
def method_missing(name, *args, &block) | |
if Array.public_instance_methods.include?(name) | |
to_a.send(name, *args, &block) | |
else | |
super | |
end | |
end | |
def respond_to_missing?(name, include_private) | |
array_methos = include_private ? Array.instance_methods : Array.public_instance_methods | |
if array_methos.include?(name) | |
true | |
else | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment