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



7
8
9
# File 'lib/basic101/basic_integer.rb', line 7

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

Instance Method Details

#and(other) ⇒ Object



19
20
21
# File 'lib/basic101/basic_integer.rb', line 19

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

#chrObject



31
32
33
34
# File 'lib/basic101/basic_integer.rb', line 31

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

#notObject



27
28
29
# File 'lib/basic101/basic_integer.rb', line 27

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

#or(other) ⇒ Object



23
24
25
# File 'lib/basic101/basic_integer.rb', line 23

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

#strObject



36
37
38
# File 'lib/basic101/basic_integer.rb', line 36

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

#to_floatObject



15
16
17
# File 'lib/basic101/basic_integer.rb', line 15

def to_float
  BasicFloat.new(@value)
end

#to_integerObject



11
12
13
# File 'lib/basic101/basic_integer.rb', line 11

def to_integer
  self
end