Class: Proc

Inherits:
Object show all
Defined in:
lib/multiarray.rb,
lib/multiarray/gccfunction.rb

Overview

Proc#bind is defined if it does not exist already

Instance Method Summary collapse

Instance Method Details

#bind(object) ⇒ Method

Proc#bind is defined if it does not exist already

Parameters:

  • object (Object)

    Object to bind this instance of Proc to.

Returns:

  • (Method)

    The bound method.



56
57
58
59
60
61
62
63
64
65
# File 'lib/multiarray.rb', line 56

def bind( object )
  block, time = self, Time.now
  ( class << object; self end ).class_eval do
    method_name = "__bind_#{time.to_i}_#{time.usec}"
    define_method method_name, &block
    method = instance_method method_name
    remove_method method_name
    method
  end.bind object
end

#while(&action) ⇒ NilClass

An overloadable while loop

Parameters:

  • action (Proc)

    The loop body

Returns:



76
77
78
79
# File 'lib/multiarray.rb', line 76

def while( &action )
  action.call while call.get
  nil
end

#while_with_gcc(&action) ⇒ NilClass

Overloaded while loop for handling compilation

Parameters:

  • action (Proc)

    The loop body

Returns:



205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/multiarray/gccfunction.rb', line 205

def while_with_gcc( &action )
  function = Thread.current[ :function ]
  if function
    function << "#{function.indent}while ( 1 ) {\n"
    function.indent_offset +1
    function << "#{function.indent}if ( !( #{call.get}) ) break;\n"
    action.call
    function.indent_offset -1
    function << "#{function.indent}}\n"
    nil
  else
    while_without_gcc &action
  end
end