Class: Ordinary::Unit
- Inherits:
-
Object
- Object
- Ordinary::Unit
- Includes:
- Composable
- Defined in:
- lib/ordinary/unit.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
-
#requirements ⇒ Object
readonly
Returns the value of attribute requirements.
Instance Method Summary collapse
-
#initialize(original_unit, requirements = nil, arguments = [], &process) ⇒ Unit
constructor
A new instance of Unit.
- #inspect ⇒ Object
- #to_proc ⇒ Object
- #with(*arguments) ⇒ Object
Methods included from Composable
#<<, #>>, #instance_id, #owned?, #owned_by, #owner
Constructor Details
#initialize(original_unit, requirements = nil, arguments = [], &process) ⇒ Unit
Returns a new instance of Unit.
33 34 35 36 37 38 39 |
# File 'lib/ordinary/unit.rb', line 33 def initialize(original_unit, requirements = nil, arguments = [], &process) raise ArgumentError, 'block not supplied' unless block_given? @original_unit = original_unit @requirements = requirements @arguments = arguments @process = process end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
43 44 45 |
# File 'lib/ordinary/unit.rb', line 43 def arguments @arguments end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
45 46 47 |
# File 'lib/ordinary/unit.rb', line 45 def process @process end |
#requirements ⇒ Object (readonly)
Returns the value of attribute requirements.
41 42 43 |
# File 'lib/ordinary/unit.rb', line 41 def requirements @requirements end |
Instance Method Details
#inspect ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ordinary/unit.rb', line 57 def inspect original_owner = '' if @original_unit argument_list = @arguments.map(&:inspect) * ', ' original_owner = " (#{@original_unit.owner} with [#{argument_list}])" end "#<#{instance_id} #{owner}#{original_owner}>" end |
#to_proc ⇒ Object
51 52 53 54 55 |
# File 'lib/ordinary/unit.rb', line 51 def to_proc @requirements.load if @requirements and !@requirements.loaded? args = @arguments + (@original_unit ? @original_unit.arguments : []) lambda { |value| @process.call(value, *args) } end |
#with(*arguments) ⇒ Object
47 48 49 |
# File 'lib/ordinary/unit.rb', line 47 def with(*arguments) self.class.new(self, @requirements, arguments, &@process) end |