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.



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

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.



392
393
394
395
396
397
398
399
# File 'lib/multiarray.rb', line 392

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.



409
410
411
412
413
414
415
416
# File 'lib/multiarray.rb', line 409

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.



426
427
428
429
430
431
432
433
# File 'lib/multiarray.rb', line 426

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.



497
498
499
# File 'lib/multiarray.rb', line 497

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.



479
480
481
482
483
484
485
486
# File 'lib/multiarray.rb', line 479

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.



443
444
445
446
447
448
449
450
# File 'lib/multiarray.rb', line 443

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.



460
461
462
463
464
465
466
467
# File 'lib/multiarray.rb', line 460

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