Class: NamedProc

Inherits:
Proc show all
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

Modules: Object, Proxy

Constant Summary collapse

VERSION =
"1.2"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (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

#inspectObject



10
11
12
# File 'lib/named_proc/implementation.rb', line 10

def inspect
  super.sub /^#<#{self.class}/, "#<#{self.class}[#{name}]"
end