Class: Fixnum

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

Overview

Some methods of Fixnum are modified

Instance Method Summary collapse

Instance Method Details

#drandFloat

Generate random number

Generate a random number greater or equal to zero and lower than this number.

Returns:

  • (Float)

    A random number.



514
515
516
# File 'lib/multiarray.rb', line 514

def drand
  self * Kernel.rand
end

#intand_with_hornetseye(other) ⇒ Object

& is modified to work with this library

Parameters:

  • other (Object)

    Second operand for binary and operation.

Returns:

  • (Object)

    Result of binary operation.



400
401
402
403
404
405
406
407
# File 'lib/multiarray.rb', line 400

def intand_with_hornetseye( other )
  if other.is_a? Integer
    intand_without_hornetseye other
  else
    x, y = other.coerce self
    x & y
  end
end

#intor_with_hornetseye(other) ⇒ Object

| is modified to work with this library

Parameters:

  • other (Object)

    Second operand for binary or operation.

Returns:

  • (Object)

    Result of binary operation.



417
418
419
420
421
422
423
424
# File 'lib/multiarray.rb', line 417

def intor_with_hornetseye( other )
  if other.is_a? Integer
    intor_without_hornetseye other
  else
    x, y = other.coerce self
    x | y
  end
end

#intxor_with_hornetseye(other) ⇒ Object

^ is modified to work with this library

Parameters:

  • other (Object)

    Second operand for binary xor operation.

Returns:

  • (Object)

    Result of binary operation.



434
435
436
437
438
439
440
441
# File 'lib/multiarray.rb', line 434

def intxor_with_hornetseye( other )
  if other.is_a? Integer
    intxor_without_hornetseye other
  else
    x, y = other.coerce self
    x ^ y
  end
end

#lrandInteger

Generate random number

Generate a random number greater or equal to zero and lower than this number.

Returns:

  • (Integer)

    A random number.



505
506
507
# File 'lib/multiarray.rb', line 505

def lrand
  Kernel.rand self
end

#power_with_hornetseye(other) ⇒ Object

** is modified to work with this library

Parameters:

  • other (Object)

    Second operand for binary operation.

Returns:

  • (Object)

    Result of binary operation.



487
488
489
490
491
492
493
494
# File 'lib/multiarray.rb', line 487

def power_with_hornetseye( other )
  if other.matched?
    x, y = other.coerce self
    x ** y
  else
    power_without_hornetseye other
  end
end

#power_with_rgb(other) ⇒ Object

** is modified to work with RGB values

Parameters:

  • other (Object)

    Second operand for binary operation.

Returns:

  • (Object)

    Result of binary operation.



923
924
925
926
927
928
929
930
# File 'lib/multiarray/rgb.rb', line 923

def power_with_rgb(other)
  if other.is_a? Hornetseye::RGB
    x, y = other.coerce self
    x ** y
  else
    power_without_rgb other
  end
end

#shl_with_hornetseye(other) ⇒ Object

<< is modified to work with this library

Parameters:

  • other (Object)

    Second operand for binary shl operation.

Returns:

  • (Object)

    Result of binary operation.



451
452
453
454
455
456
457
458
# File 'lib/multiarray.rb', line 451

def shl_with_hornetseye( other )
  if other.is_a? Integer
    shl_without_hornetseye other
  else
    x, y = other.coerce self
    x << y
  end
end

#shr_with_hornetseye(other) ⇒ Object

>> is modified to work with this library

Parameters:

  • other (Object)

    Second operand for binary shr operation.

Returns:

  • (Object)

    Result of binary operation.



468
469
470
471
472
473
474
475
# File 'lib/multiarray.rb', line 468

def shr_with_hornetseye( other )
  if other.is_a? Integer
    shr_without_hornetseye other
  else
    x, y = other.coerce self
    x >> y
  end
end