Class: Basic101::BasicInteger

Inherits:
BasicNumeric show all
Defined in:
lib/basic101/basic_integer.rb

Instance Attribute Summary

Attributes inherited from BasicNumeric

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicNumeric

#<=>, #abs, #cos, #exp, #initialize, #log, #negate, #print_new_line, #print_string, #sgn, #simplest, #sin, #sqr, #tan, #to_b, #to_f, #to_i, #to_numeric

Methods included from BasicMath

basic_math_op

Methods included from BasicComparisons

comparison_op

Methods inherited from BasicObject

#eval, #to_numeric, #to_string, #type_name, type_name

Constructor Details

This class inherits a constructor from Basic101::BasicNumeric

Class Method Details

.from_bool(b) ⇒ Object



9
10
11
# File 'lib/basic101/basic_integer.rb', line 9

def self.from_bool(b)
  new(b ? -1 : 0)
end

Instance Method Details

#and(other) ⇒ Object



21
22
23
# File 'lib/basic101/basic_integer.rb', line 21

def and(other)
  self.class.new(value & other.to_integer.value)
end

#chrObject



33
34
35
36
# File 'lib/basic101/basic_integer.rb', line 33

def chr
  raise InvalidArgumentError unless (0..255).include?(@value)
  BasicString.new(@value.chr)
end

#notObject



29
30
31
# File 'lib/basic101/basic_integer.rb', line 29

def not
  self.class.new(~value)
end

#or(other) ⇒ Object



25
26
27
# File 'lib/basic101/basic_integer.rb', line 25

def or(other)
  self.class.new(value | other.to_integer.value)
end

#strObject



38
39
40
# File 'lib/basic101/basic_integer.rb', line 38

def str
  BasicString.new(@value.to_s)
end

#to_floatObject



17
18
19
# File 'lib/basic101/basic_integer.rb', line 17

def to_float
  BasicFloat.new(@value)
end

#to_integerObject



13
14
15
# File 'lib/basic101/basic_integer.rb', line 13

def to_integer
  self
end