Class: NamedProc
- Defined in:
- lib/named_proc/implementation.rb,
lib/named_proc/version.rb
Overview
Class for a proc that’s got a name
Defined Under Namespace
Constant Summary collapse
- VERSION =
"1.2"
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.create(name, block, create_lambda = false) ⇒ Object
Create a named proc from a given proc/lambda object.
Instance Method Summary collapse
-
#initialize(name) ⇒ NamedProc
constructor
A new instance of NamedProc.
- #inspect ⇒ Object
Constructor Details
#initialize(name) ⇒ NamedProc
Returns a new instance of NamedProc.
5 6 7 8 |
# File 'lib/named_proc/implementation.rb', line 5 def initialize(name) @name = name super() end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/named_proc/implementation.rb', line 3 def name @name end |
Class Method Details
.create(name, block, create_lambda = false) ⇒ Object
Create a named proc from a given proc/lambda object
15 16 17 18 19 20 21 22 |
# File 'lib/named_proc/implementation.rb', line 15 def self.create(name, block, create_lambda = false) if create_lambda lambdafyer = Module.new lambdafyer.singleton_class.send(:define_method, :lambdafy, &block) block = lambdafyer.method(:lambdafy).to_proc end new(name.to_sym, &block) end |
Instance Method Details
#inspect ⇒ Object
10 11 12 |
# File 'lib/named_proc/implementation.rb', line 10 def inspect super.sub /^#<#{self.class}/, "#<#{self.class}[#{name}]" end |