Class: Rubyfocus::SearchableArray

Inherits:
Object
  • Object
show all
Includes:
Searchable
Defined in:
lib/rubyfocus/includes/searchable.rb

Overview

A sample class, SearchableArray, is basically a wrapper around a standard array

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Searchable

#find, #select

Constructor Details

#initialize(*args, &blck) ⇒ SearchableArray

Takes the same arguments as the array it wraps



69
70
71
# File 'lib/rubyfocus/includes/searchable.rb', line 69

def initialize(*args, &blck)
  @array = Array.new(*args, &blck)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blck) ⇒ Object

In all other respects, it’s an array - handily governed by this method



74
75
76
77
78
79
80
# File 'lib/rubyfocus/includes/searchable.rb', line 74

def method_missing meth, *args, &blck
  if @array.respond_to?(meth)
    @array.send(meth, *args, &blck)
  else
    super(meth, *args, &blck)
  end
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



66
67
68
# File 'lib/rubyfocus/includes/searchable.rb', line 66

def array
  @array
end