ruby - Customizing IRB output -


i've created class called specialarray , i'd customize sort of output irb shows. currently, when create new instance of class, irb returns entire object. see:

1.9.3p194 :022 > specialarray.new([1,2,0,6,2,11])  => #<uniquearray:0x007ff05b026ec8 @input=[1, 2, 0, 6, 2, 11], @output=[1, 2, 0, 6, 11]> 

but i'd show i've defined output. in other words, i'd see this.

1.9.3p194 :022 > specialarray.new([1,2,0,6,2,11])  => [1, 2, 0, 6, 11] 

what need specify irb should display output?

solution:

this method ended creating.

def inspect   output.inspect end 

irb calls object#inspect method string representation of object. need override method that:

class foo   def inspect     "foo:#{object_id}"   end end 

then in irb you'll get:

>> foo.new => foo:70250368430260  

in particular case make specialarray#inspect return string representation of underlying array, e.g.:

specialarray   def inspect     @output.inspect   end end 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -