From: Tobias Reif Date: 2001-09-20T20:02:21+09:00 Subject: [ruby-talk:21430] chain methods inside and outside the class; how to intermingle mine and Strings' methods? Hi; I'm trying to understand objects, and instance @variables. Now I have two questions: -- # this is just a learning file, and a test model for a real program # question 1 of 2: how to code it more appropriately/the Ruby way? class HoX < String def initialize s @s = s end def give_string return @s.to_s end def delete_digits HoX.new @s.gsub /\d/,'' end def repeat HoX.new @s.dup * 2 end def all # chain method calls here delete_digits.repeat end end h = HoX.new '68a345b89798c' # also chain method calls here all_HoX_meths = h.all.give_string # and chain them here, with String methods all_HoX_plus_string_meths = h.delete_digits.repeat.give_string.upcase.reverse.chop.capitalize.swapcase # question 2: how to make it possible to write: # intermingled = h.upcase.repeat.chop # perhaps to_s puts all_HoX_meths , all_HoX_plus_string_meths #-> abcabc #-> cBACB -- Tobi -- Tobias Reif http://www.pinkjuice.com/myDigitalProfile.xhtml go_to('www.ruby-lang.org').get(ruby).play.create.have_fun http://www.pinkjuice.com/ruby/