Class: Fixnum
Instance Method Summary collapse
- #[](*args) ⇒ Object
-
#cycles ⇒ Object
(also: #cycle)
Extend Fixnum to enable 10.cycles.
- #old_bit_select ⇒ Object
- #ones_comp(num_bits) ⇒ Object (also: #ones_complement, #ones_compliment)
- #to_bool ⇒ Object
Instance Method Details
#[](*args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/origen/core_ext/fixnum.rb', line 16 def [](*args) if args.length == 1 && !args.first.is_a?(Range) old_bit_select(args.first) else if args.first.is_a?(Range) msb = args.first.first lsb = args.first.last else msb = args.first lsb = args.last end (self >> lsb) & 0.ones_comp(msb - lsb + 1) end end |
#cycles ⇒ Object Also known as: cycle
Extend Fixnum to enable 10.cycles
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/origen/core_ext/fixnum.rb', line 3 def cycles if block_given? times do yield Origen.app.tester.cycle end else Origen.app.tester.cycle(repeat: self) end end |
#old_bit_select ⇒ Object
15 |
# File 'lib/origen/core_ext/fixnum.rb', line 15 alias_method :old_bit_select, :[] |
#ones_comp(num_bits) ⇒ Object Also known as: ones_complement, ones_compliment
31 32 33 |
# File 'lib/origen/core_ext/fixnum.rb', line 31 def ones_comp(num_bits) self ^ ((1 << num_bits) - 1) end |
#to_bool ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/origen/core_ext/fixnum.rb', line 37 def to_bool if self == 1 return true elsif self == 0 return false else return nil end end |