Module: OpenHAB::Core::LazyArray

Includes:
Enumerable
Included in:
Items::GroupItem::Members, Items::Registry, Rules::Registry, Rules::TaggedArray, Things::Registry, Types::TimeSeries
Defined in:
lib/openhab/core/lazy_array.rb

Overview

Common base class for array-like collections that have lookup methods to avoid instantiating the elements if you only use the lookup method

your class should implement to_a

Instance Method Summary collapse

Methods included from Enumerable

#all_groups, #all_members, #command, #command!, #decrease, #down, #equipments, #fast_forward, #groups, #increase, #locations, #member_of, #members, #move, #next, #not_member_of, #not_tagged, #off, #on, #pause, #play, #points, #previous, #refresh, #rewind, #stop, #tagged, #toggle, #up, #update, #update!

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delegate any other methods to the actual array, exclude mutating methods



38
39
40
41
42
# File 'lib/openhab/core/lazy_array.rb', line 38

def method_missing(method, *args, &block)
  return to_a.send(method, *args, &block) if method[-1] != "!" && Array.instance_methods.include?(method)

  super
end

Instance Method Details

#each(&block) ⇒ Object

Calls the given block once for each object, passing that object as a parameter. Returns self.

If no block is given, an Enumerator is returned.



24
25
26
27
# File 'lib/openhab/core/lazy_array.rb', line 24

def each(&block)
  to_a.each(&block)
  self
end

#to_aryArray

Implicitly convertible to array

Returns:



33
34
35
# File 'lib/openhab/core/lazy_array.rb', line 33

def to_ary
  to_a
end