Created
August 30, 2014 23:28
-
-
Save havenwood/52cf87e71d4709dfa556 to your computer and use it in GitHub Desktop.
Klass Module
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 Klass | |
def self.new *args, &block | |
object = Class.allocate | |
object.send :initialize, *args, &block | |
object | |
end | |
end | |
Cat = Klass.new do | |
attr_reader :name, :age | |
def initialize name, age | |
@name, @age = name, age | |
end | |
end | |
cat = Cat.new 'Mr. Fluffles', 9 | |
#=> #<Cat:0x007ffb7da1bca8 @name="Mr. Fluffles", @age=9> | |
cat.name | |
#=> "Mr. Fluffles" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment