Sha256: 9025f3b82208424c39c5d3d62de273322efc0ff4e118c7ef8f3c36d908b905c1

Contents?: true

Size: 914 Bytes

Versions: 113

Compression:

Stored size: 914 Bytes

Contents

class Fixnum
  # Extend Fixnum to enable 10.cycles
  def cycles
    if block_given?
      times do
        yield
        Origen.app.tester.cycle
      end
    else
      Origen.app.tester.cycle(repeat: self)
    end
  end
  alias_method :cycle, :cycles

  alias_method :old_bit_select, :[]
  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

  def ones_comp(num_bits)
    self ^ ((1 << num_bits) - 1)
  end
  alias_method :ones_complement, :ones_comp
  alias_method :ones_compliment, :ones_comp

  def to_bool
    if self == 1
      return true
    elsif self == 0
      return false
    else
      return nil
    end
  end
end

Version data entries

113 entries across 113 versions & 1 rubygems

Version Path
origen-0.25.0 lib/origen/core_ext/fixnum.rb
origen-0.24.0 lib/origen/core_ext/fixnum.rb
origen-0.23.0 lib/origen/core_ext/fixnum.rb
origen-0.22.0 lib/origen/core_ext/fixnum.rb
origen-0.21.0 lib/origen/core_ext/fixnum.rb
origen-0.20.3 lib/origen/core_ext/fixnum.rb
origen-0.20.2 lib/origen/core_ext/fixnum.rb
origen-0.20.1 lib/origen/core_ext/fixnum.rb
origen-0.20.0 lib/origen/core_ext/fixnum.rb
origen-0.13.0 lib/origen/core_ext/fixnum.rb
origen-0.12.1 lib/origen/core_ext/fixnum.rb
origen-0.12.0 lib/origen/core_ext/fixnum.rb
origen-0.11.0 lib/origen/core_ext/fixnum.rb
origen-0.10.1 lib/origen/core_ext/fixnum.rb
origen-0.9.1 lib/origen/core_ext/fixnum.rb
origen-0.9.0 lib/origen/core_ext/fixnum.rb
origen-0.8.0 lib/origen/core_ext/fixnum.rb
origen-0.7.47 lib/origen/core_ext/fixnum.rb
origen-0.7.46 lib/origen/core_ext/fixnum.rb
origen-0.7.45 lib/origen/core_ext/fixnum.rb