Module: Tins::ProcPrelude

Included in:
Proc
Defined in:
lib/tins/proc_prelude.rb

Instance Method Summary collapse

Instance Method Details

#apply(&my_proc) ⇒ Object



5
6
7
8
# File 'lib/tins/proc_prelude.rb', line 5

def apply(&my_proc)
  my_proc or raise ArgumentError, 'a block argument is required'
  lambda { |list| my_proc.call(*list) }
end

#arrayObject



20
21
22
# File 'lib/tins/proc_prelude.rb', line 20

def array
  lambda { |*list| list }
end

#call(obj, &my_proc) ⇒ Object



15
16
17
18
# File 'lib/tins/proc_prelude.rb', line 15

def call(obj, &my_proc)
  my_proc or raise ArgumentError, 'a block argument is required'
  obj.instance_eval(&my_proc)
end

#const(konst = nil, &my_proc) ⇒ Object



58
59
60
61
# File 'lib/tins/proc_prelude.rb', line 58

def const(konst = nil, &my_proc)
  konst ||= my_proc.call
  lambda { |*_| konst }
end

#firstObject Also known as: head



25
26
27
# File 'lib/tins/proc_prelude.rb', line 25

def first
  lambda { |*list| list.first }
end

#from(&block) ⇒ Object



67
68
69
70
71
# File 'lib/tins/proc_prelude.rb', line 67

def from(&block)
  my_method, binding = block.call, block.binding
  my_self = eval 'self', binding
  lambda { |*list| my_self.__send__(my_method, *list) }
end

#id1Object



53
54
55
# File 'lib/tins/proc_prelude.rb', line 53

def id1
  lambda { |obj| obj }
end

#lastObject



42
43
44
# File 'lib/tins/proc_prelude.rb', line 42

def last
  lambda { |*list| list.last }
end

#map_apply(my_method, *args, &my_proc) ⇒ Object



10
11
12
13
# File 'lib/tins/proc_prelude.rb', line 10

def map_apply(my_method, *args, &my_proc)
  my_proc or raise ArgumentError, 'a block argument is required'
  lambda { |x, y| my_proc.call(x, y.__send__(my_method, *args)) }
end

#nth(n) ⇒ Object



63
64
65
# File 'lib/tins/proc_prelude.rb', line 63

def nth(n)
  lambda { |*list| list[n] }
end

#rotate(n = 1) ⇒ Object Also known as: swap



47
48
49
# File 'lib/tins/proc_prelude.rb', line 47

def rotate(n = 1)
  lambda { |*list| list.rotate(n) }
end

#secondObject



32
33
34
# File 'lib/tins/proc_prelude.rb', line 32

def second
  lambda { |*list| list[1] }
end

#tailObject



37
38
39
# File 'lib/tins/proc_prelude.rb', line 37

def tail
  lambda { |*list| list[1..-1] }
end