Module: HDLRuby::High::Std::HEnumArg

Included in:
HEnumerator
Defined in:
lib/HDLRuby/std/hruby_enum.rb

Overview

Module adding args in enumeration functionalities to object including the to_a method.

Instance Method Summary collapse

Instance Method Details

#heach_range(rng, &ruby_block) ⇒ Object

Iterator on each of the elements in range +rng+. NOTE:

  • Stop iteration when the end of the range is reached or when there are no elements left
  • This is not a method from Ruby but one specific for hardware where creating a array is very expensive.


763
764
765
766
767
768
769
# File 'lib/HDLRuby/std/hruby_enum.rb', line 763

def heach_range(rng,&ruby_block)
  # No block given, returns a new enumerator.
  if !ruby_block then
    return HEnumeratorWrapper.new(self,:heach_range)
  end
  return self.to_a.each_range(rng,&ruby_block)
end

#hwith_index(&ruby_block) ⇒ Object

Iterates with an index.



772
773
774
775
776
777
778
779
780
781
782
783
784
# File 'lib/HDLRuby/std/hruby_enum.rb', line 772

def hwith_index(&ruby_block)
  # No block given, returns a new enumerator.
  if !ruby_block then
    return HEnumeratorWrapper.new(self,:hwith_index)
  end
  # return self.hto_a.each_with_index(&ruby_block)
  i = 0
  return self.heach do |e|
    res = ruby_block.call(e,i)
    i += 1
    res
  end
end

#hwith_object(obj) ⇒ Object

Return a new HEnumerator with an arbitrary arbitrary object +obj+.



787
788
789
790
791
792
793
794
795
796
# File 'lib/HDLRuby/std/hruby_enum.rb', line 787

def hwith_object(obj)
  # No block given, returns a new enumerator.
  if !ruby_block then
    return HEnumeratorWrapper.new(self,:with_object)
  end
  # return self.hto_a.each_with_object(&ruby_block)
  return self.heach do |e|
    ruby_block.call(e,obj)
  end
end