-
-
Save nico-abram/afdbd2df0aadc97e43745740e827727c to your computer and use it in GitHub Desktop.
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
class Trait | |
attr_accessor :methodHash | |
def self.define(&bloque) | |
a = Trait.new | |
a.methodHash = Hash.new | |
a.instance_eval(&bloque) | |
end | |
def name(sym) | |
Object.const_set(sym, self) | |
end | |
# Agregar el metodo sym con el codigo bloque | |
def method(sym, &bloque) | |
puts methodHash | |
puts sym | |
puts bloque | |
methodHash[sym] = bloque | |
end | |
end | |
class Class | |
def uses(traitObj) | |
traitObj.methodHash.each do |sym, bloque| | |
self.send(:define_method, sym, &bloque) | |
end | |
end | |
end | |
Trait.define do | |
name :A | |
method :h do | |
"H" | |
end | |
end | |
class B uses A end | |
# B.new.h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment