Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/to_proc/core/Array.rb

Instance Method Summary collapse

Instance Method Details

#to_procObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/to_proc/core/Array.rb', line 2

def to_proc
  if self[0].is_a? Symbol
    method, *arguments = self
    -> receiver { receiver.send method, *arguments }
  elsif self[1].is_a? Symbol
    receiver, method, *arguments = self
    if arguments.empty?
      -> argument { receiver.send method, argument }
    else
      # if some arguments were passed as well,
      # what is more reasonable for collection element?
      # to become the first or the last argument?
    end
  else
    arguments = self
    -> receiver { receiver.to_proc[*arguments] }
  end
end