Created
March 5, 2015 03:18
-
-
Save vic/3c0e87cc1e465fa02f0b to your computer and use it in GitHub Desktop.
Elfos que aprenden a escribir y morir por convivir con los humanos.
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 Aliveness | |
attr_accessor :alive | |
def initialize | |
@alive = true | |
end | |
end | |
module DieAbility | |
include Aliveness | |
def die | |
@alive = false | |
end | |
end | |
module Nerudability | |
def write | |
puts "Puedo escribir los versos mas tristes esta noche" | |
end | |
end | |
class Humano | |
include DieAbility | |
include Nerudability | |
attr_accessor :name | |
end | |
class Pato | |
include DieAbility | |
def fly | |
puts "fly fly fly" | |
end | |
def method_missing(method_name, *args) | |
if method_name.to_s =~ /ca+nta+|si+ng/i | |
puts "A lala lala long" | |
else | |
puts "No se #{method_name} porque soy un #{self.class}" | |
end | |
end | |
end | |
class Elfo | |
include Aliveness | |
attr_accessor :name | |
def think | |
puts "Oh #{self.name} is so smart" | |
end | |
end | |
puts "I'm #{self}, the world is ready, let's play." | |
a = Elfo.new | |
b = Elfo.new | |
class << b | |
include Nerudability | |
end | |
# extend abre tu personalidad e incluye un modulo en ella. | |
b.extend Nerudability | |
# un elfo que tambien puede escribir | |
b.name = "zura" | |
b.write | |
b.think | |
# estas son constantes | |
PI = 3.1416 | |
USD_RATE = 12.5 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment