Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created August 30, 2014 23:28
Show Gist options
  • Save havenwood/52cf87e71d4709dfa556 to your computer and use it in GitHub Desktop.
Save havenwood/52cf87e71d4709dfa556 to your computer and use it in GitHub Desktop.
Klass Module
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