Class: Machinist::Lathe
- Inherits:
-
Object
- Object
- Machinist::Lathe
- Defined in:
- lib/machinist/lathe.rb
Overview
When you make an object, the blueprint for that object is instance-evaled against a Lathe.
The Lathe implements all the methods that are available to the blueprint, including method_missing to let the blueprint define attributes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the object under construction.
Instance Method Summary collapse
-
#initialize(klass, serial_number, attributes = {}) ⇒ Lathe
constructor
A new instance of Lathe.
-
#method_missing(attribute, *args, &block) ⇒ Object
:nodoc:.
-
#sn ⇒ Object
Returns a unique serial number for the object under construction.
Constructor Details
#initialize(klass, serial_number, attributes = {}) ⇒ Lathe
Returns a new instance of Lathe.
8 9 10 11 12 13 14 15 |
# File 'lib/machinist/lathe.rb', line 8 def initialize(klass, serial_number, attributes = {}) @klass = klass @serial_number = serial_number @assigned_attributes = {} @object = @klass.new attributes.each { |key, value| assign_attribute(key, value) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(attribute, *args, &block) ⇒ Object
:nodoc:
25 26 27 28 29 |
# File 'lib/machinist/lathe.rb', line 25 def method_missing(attribute, *args, &block) #:nodoc: unless attribute_assigned?(attribute) assign_attribute(attribute, make_attribute(attribute, args, &block)) end end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the object under construction.
23 24 25 |
# File 'lib/machinist/lathe.rb', line 23 def object @object end |
Instance Method Details
#sn ⇒ Object
Returns a unique serial number for the object under construction.
18 19 20 |
# File 'lib/machinist/lathe.rb', line 18 def sn @serial_number end |