From: Robert Klemme Date: 2009-01-04T23:48:59+09:00 Subject: Re: VERY simple question about "?" On 04.01.2009 14:48, Tom Cloyd wrote: > I guess what confused me is that I bring to Ruby the notion that if a > symbol causes something to happen, as "?" clearly does in my example (it > produces the integer code for a character), In this case nothing "happens" (see below). It is just another syntactical way to express an integer constant. > its' an operator or method. > I'm not unfamiliar with linguistics. I don't see the equivalence between > a string delimiter, or a character that signals the beginning of a > symbol, and a symbol that is actually productive of something. Makes no > sense to me at all, in fact. Maybe I'm failing to grasp some > transformative concept which changes how things work in the Ruby world. > > Seeing operators as methods makes some real sense, on the other hand. > "=" produces something out of what it's given. It doesn't just change > meaning, which is all that happens with quotes or ":". That's the > distinction I'm seeing, and it seems valid. I am not sure what you mean by "change meaning". Can you elaborate? Btw, note that there are two types of "=": 1. variable assignment as in "a = 123", 2. method call that mimics variable assignment as in "a.foo = 456". Both evaluate always to the right hand side - but this is about the only commonality. Semantics of type 1 is fixed while you are free to implement type 2 in any way you like, e.g. irb(main):005:0> a = Object.new => # irb(main):006:0> def a.foo=(x) puts "bah!" end => nil irb(main):007:0> a.foo = 456 bah! => 456 irb(main):008:0> > I'll keep thinking about it. Basically "?a" is just another textual representation for the integer 97 which happens to be the ASCII code of character "a". It differs from string delimiters because the expression "foo" is actually a String constructor - it will create a new String object whenever it is executed: irb(main):003:0> 3.times { x = "foo"; puts x, x.object_id } foo 1073491940 foo 1073492040 foo 1073491880 => 3 irb(main):004:0> > Quite apart from this is the strange matter of how difficult it is to > find a simple, complete table of Ruby operators. I've basically given up > on that. You can find it in the Pickaxe - a good book to have anyway. > Thanks for the Pickaxe reference - I found it on PDF p. 332 of my PDF > version of the 2nd ed. I'd never seen that page. As far as I know there is no legal electronic version of the second edition so you better double check whether you are allowed to use this. You could as well buy the book to somewhat compensate for this. Kind regards robert