Class: Ame::Method
- Inherits:
-
Object
- Object
- Ame::Method
- Defined in:
- lib/ame-1.0/method.rb
Overview
A method in its defined state.
Defined Under Namespace
Classes: Undefined
Instance Attribute Summary collapse
-
#arguments ⇒ Arguments
readonly
The arguments of the receiver.
-
#description ⇒ String
readonly
The description of the receiver.
-
#options ⇒ Options
readonly
The options of the receiver.
Class Method Summary collapse
-
.name(ruby_name) ⇒ String
The command-line version of RUBY_NAME, replacing any ‘_’ with ‘-’.
-
.ruby_name(name) ⇒ Symbol
The Ruby version of NAME, possibly the name of the method given on the command-line, replacing any ‘-’ with ‘_’.
Instance Method Summary collapse
-
#call(instance, arguments = nil, options = nil) ⇒ self
Call the receiver’s method on INSTANCE with ARGUMENTS and OPTIONS, retrieving any default values for them if they’re nil.
-
#initialize(ruby_name, klass, description, options, arguments) ⇒ Method
constructor
A new instance of Method.
-
#name ⇒ String
The command-line name of the receiver.
- #process(instance, arguments) ⇒ self
-
#qualified_name ⇒ String
The full command-line name of the receiver, including the class that this method belongs to’s Class.fullname.
Constructor Details
#initialize(ruby_name, klass, description, options, arguments) ⇒ Method
Returns a new instance of Method.
22 23 24 25 |
# File 'lib/ame-1.0/method.rb', line 22 def initialize(ruby_name, klass, description, , arguments) @ruby_name, @class, @description, @options, @arguments = ruby_name, klass, description, , arguments end |
Instance Attribute Details
#arguments ⇒ Arguments (readonly)
Returns The arguments of the receiver.
63 64 65 |
# File 'lib/ame-1.0/method.rb', line 63 def arguments @arguments end |
#description ⇒ String (readonly)
Returns The description of the receiver.
57 58 59 |
# File 'lib/ame-1.0/method.rb', line 57 def description @description end |
#options ⇒ Options (readonly)
Returns The options of the receiver.
60 61 62 |
# File 'lib/ame-1.0/method.rb', line 60 def @options end |
Class Method Details
.name(ruby_name) ⇒ String
Returns The command-line version of RUBY_NAME, replacing any ‘_’ with ‘-’.
17 18 19 |
# File 'lib/ame-1.0/method.rb', line 17 def name(ruby_name) ruby_name.to_s.gsub('_', '-') end |
.ruby_name(name) ⇒ Symbol
Returns The Ruby version of NAME, possibly the name of the method given on the command-line, replacing any ‘-’ with ‘_’.
10 11 12 |
# File 'lib/ame-1.0/method.rb', line 10 def ruby_name(name) name.gsub('-', '_').to_sym end |
Instance Method Details
#call(instance, arguments = nil, options = nil) ⇒ self
Call the receiver’s method on INSTANCE with ARGUMENTS and OPTIONS, retrieving any default values for them if they’re nil.
49 50 51 52 53 54 |
# File 'lib/ame-1.0/method.rb', line 49 def call(instance, arguments = nil, = nil) , _ = @options.process([]) unless arguments ||= @arguments.process(, []) instance.send @ruby_name, *(arguments + (.empty? ? [] : [])) self end |
#name ⇒ String
Returns The command-line name of the receiver.
66 67 68 |
# File 'lib/ame-1.0/method.rb', line 66 def name @name ||= self.class.name(@ruby_name) end |
#process(instance, arguments) ⇒ self
35 36 37 38 |
# File 'lib/ame-1.0/method.rb', line 35 def process(instance, arguments) , remainder = @options.process(arguments) call(instance, @arguments.process(, remainder), ) end |
#qualified_name ⇒ String
Returns The full command-line name of the receiver, including the class that this method belongs to’s Class.fullname.
72 73 74 |
# File 'lib/ame-1.0/method.rb', line 72 def qualified_name [@class.fullname, name].reject(&:empty?).join(' ') end |