Skip to content

Instantly share code, notes, and snippets.

@techno-tanoC
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techno-tanoC/15e12f4ff5829d57df16 to your computer and use it in GitHub Desktop.
Save techno-tanoC/15e12f4ff5829d57df16 to your computer and use it in GitHub Desktop.
extractor.rb
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