il Wed, 04 Feb 2004 23:49:02 GMT, caligari <il_piccione / blu.it> ha scritto:: >Hi all, i'm new to ruby and i find it very exciting, but i've two little >question that i cannot find answers for. ciao :) >First: how can i use a variable name within a regex? In other words, i >explain it with some perl code: dunno perl, but possibly you mean something like this: >> a='spira' => "spira" >> puts 'yes' if 'supercalifragilistichespiralidoso'=~ /#{a}/ yes => nil the #{stuff} is what is used in ruby for strings interpolation, but works in regexen too :) > >Second: this is a question on the object orientation consistency of ruby >(i'm not doubt that ruby is consistent, but i'm only a newbie that >search for answers...). >If i declare an instance variale as attr_accessor, i can avoid to write >getter/setter methods, but how can i surely give a value to a variable >without writing the relative method?? you can't. attr_* avoids you to write def myattr @myattr end or def myattr=(x) @myattr=x end that you could be forced to write cause in ruby every instance var is private. But I'm afraid you still need to tell ruby how to check something if you actually need that.