Ruby talk for austinonrails
<< >>
More deep magic: method_missing

    require 'my-csv'
    
    class Array
    
      def method_missing(meth,*args)
        meth = meth.to_s
        val = args[0]
        match = meth.match(/find_by_(\w+)/)
        field = match[1]
        self.find_all {|x| x.send(field) == val }
      end
    
    end
    
    DataRecord.make("people.txt")
    list = People.read
    found = list.find_by_height("5'10")
    
    puts found
    
    # Output:
    # People object: name=Smith, John age=35 weight=175 height=5'10
    # People object: name=Rutan, Burt age=55 weight=173 height=5'10