Class: Object

Inherits:
BasicObject
Defined in:
lib/multiarray.rb

Overview

Object is extended with a few methods

Instance Method Summary collapse

Instance Method Details

#and(other) ⇒ FalseClass, TrueClass

Boolean ‘and’ operation

Parameters:

Returns:

See Also:



122
123
124
125
126
127
128
129
# File 'lib/multiarray.rb', line 122

def and( other )
  unless other.matched?
    other
  else
    x, y = other.coerce self
    x.and y
  end
end

#conditional(a, b) ⇒ Object

Boolean select operation

Parameters:

  • a (Object)

    Object to select if self is neither false nor nil.

  • b (Object)

    Object to select if self is false or nil.

Returns:

See Also:



191
192
193
# File 'lib/multiarray.rb', line 191

def conditional( a, b )
  a.is_a?( Proc ) ? a.call : a
end

#eq(other) ⇒ FalseClass, ...

Element-wise equal operator

The method calls self == other unless other is of type Hornetseye::Node. In that case an element-wise comparison using Hornetseye::Node#eq is performed after coercion.

Returns:

See Also:



156
157
158
159
160
161
162
163
# File 'lib/multiarray.rb', line 156

def eq( other )
  unless other.matched?
    self == other
  else
    x, y = other.coerce self
    x.eq y
  end
end

#if(&action) ⇒ Object

Conditional operation

Parameters:

  • action (Proc)

    Action to perform if condition is true.

Returns:

  • (Object)

    The return value should be ignored.



200
201
202
# File 'lib/multiarray.rb', line 200

def if( &action )
  action.call
end

#if_else(action1, action2) ⇒ Object

Conditional operation

Parameters:

  • action1 (Proc)

    Action to perform if condition is true.

  • action2 (Proc)

    Action to perform if condition is false.

Returns:

  • (Object)

    The return value should be ignored.



210
211
212
# File 'lib/multiarray.rb', line 210

def if_else( action1, action2 )
  action1.call
end

#instance_exec(*arguments, &block) ⇒ Object

Object#instance_exec is defined if it does not exist already

Parameters:

  • arguments (Array<Object>)

    The arguments to pass to the block.

  • block (Proc)

    The block to be executed in the object’s environment.

Returns:

  • (Object)

    The result of executing the block.



95
96
97
# File 'lib/multiarray.rb', line 95

def instance_exec( *arguments, &block )
  block.bind( self )[ *arguments ]
end

#matched?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/multiarray.rb', line 101

def matched?
  false
end

#ne(other) ⇒ FalseClass, ...

Element-wise not-equal operator

The method calls ( self == other ).not unless other is of type Hornetseye::Node. In that case an element-wise comparison using Hornetseye::Node#ne is performed after coercion.

Returns:

See Also:



174
175
176
177
178
179
180
181
# File 'lib/multiarray.rb', line 174

def ne( other )
  unless other.matched?
    ( self == other ).not
  else
    x, y = other.coerce self
    x.ne y
  end
end

#notFalseClass

Boolean negation

Returns:

See Also:



111
112
113
# File 'lib/multiarray.rb', line 111

def not
  false
end

#or(other) ⇒ TrueClass

Boolean ‘or’ operation

Parameters:

Returns:

  • (TrueClass)

    Returns true.

See Also:



138
139
140
141
142
143
144
145
# File 'lib/multiarray.rb', line 138

def or( other )
  unless other.matched?
    self
  else
    x, y = other.coerce self
    x.or y
  end
end