Method: Oscillo::Enumerable#count

Defined in:
lib/oscillo/enumerable.rb

#countObject #count(obj) ⇒ Object #count {|value| ... } ⇒ Object

Note:

Only takes in to consideration values from the time the signal was created.

Returns the number values that the signal has had. If an argument is given, counts the number of values in the signal, for which equals to item. If a block is given, counts the number of values yielding a true value.

Overloads:

  • #countObject

    Returns number of values that the signal had.

    Returns:

    • number of values that the signal had

  • #count(obj) ⇒ Object

    Returns number of values equal to obj that the signal had.

    Parameters:

    • obj

      values to count

    Returns:

    • number of values equal to obj that the signal had

  • #count {|value| ... } ⇒ Object

    Returns number of values for which the block evaluates to true.

    Yields:

    • (value)

      gives the new value to the block

    Returns:

    • number of values for which the block evaluates to true



109
110
111
112
113
114
115
116
# File 'lib/oscillo/enumerable.rb', line 109

def count(obj=NO_ARG, &block)
  return count_with_arg(obj) unless obj.equal?(NO_ARG)
  return count_with_block(&block) if block_given?

  self.class.new(0, self) do |v, s|
    s.val + 1
  end
end