Last active
August 29, 2015 14:10
-
-
Save techno-tanoC/15e12f4ff5829d57df16 to your computer and use it in GitHub Desktop.
extractor.rb
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
module Extractable | |
module Initializer | |
def initialize *args | |
self.class.class_eval do | |
define_method(:extract) do |&block| | |
if block | |
block.(*args) | |
else | |
args | |
end | |
end | |
define_method(:match) do | |
end | |
end | |
super(*args) | |
end | |
end | |
def self.included klass | |
klass.instance_eval do | |
self.prepend Initializer | |
end | |
end | |
end | |
class Student | |
include Extractable | |
def initialize a, b | |
end | |
end | |
s = Student.new("piyo", "tyun") | |
z = "nya" | |
s.extract do |x, y| | |
p(x * 2 + y * 2 + z * 2) | |
end | |
p s.extract | |
#s.match do | |
# pattern ["hiyo", "tyun"].then do end | |
# pattern ["piyo", :x].then do end | |
# pattern [_, _].then do end | |
#end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment