On Thu, Feb 24, 2011 at 2:59 PM, 7stud -- <bbxx789_05ss / yahoo.com> wrote:
> class DataSource
>   
> cpu8001"
>  
>   > 01
>  
>
>   
> mouse241"
>  
>   > 0
>  
> end
>
> DataSource.new.methods.grep(/^get_(.*?)_info$/) do |meth|
>  > end
>
> --output:--
> ---get_cpu_info---
> ---get_mouse_info---
>
>
> class Computer
>   
>   >   >
>  ߨ勞
>
>  
>
>  
>     >
>  䨢ߣ>   䨢ߣ墮
>
>   
>  >   >  
>
>  > end
>  
>  
>
> end
>
>
>
> comp1 = Computer.new(1, DataSource.new)
> puts comp1.mouse
>
>
> --output:--
> Line 32:in `+': can't convert nil into String (TypeError)
>  >  
I'm not sure of the specifics, but $1 doesn't persist outside of the
block created in the grep statement. When you call comp1.mouse, that's
no longer within that block -- the method was defined in it, but once
it was made a method it took on an existence of its own.