Class: BlockIsArray

Inherits:
Object
  • Object
show all
Defined in:
lib/block-is-array/class.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ BlockIsArray

Returns a new instance of BlockIsArray.



2
3
4
5
# File 'lib/block-is-array/class.rb', line 2

def initialize &block
  @array = []
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/block-is-array/class.rb', line 7

def method_missing name, *args, &block
  if block
    args.push BlockIsArray.new(&block).to_array
  end

  @array.push args.unshift(name)
end

Instance Method Details

#to_arrayObject



15
16
17
# File 'lib/block-is-array/class.rb', line 15

def to_array
  @array
end