T
Tim Becker
Hi,
I just stumbled across this weird behaviour and I'm puzzled that I've
not noticed it before. If I use `attr_accessor` to define a predicate
method, i.e. one ending in a question mark, the following happens:
class Test
attr_accessor :weird?
end
t = new Test
t.weird? => nil
t.weird?=true => SyntaxError: compile error
Which is only mildly confusing, considering it's implied somewhere in
the pickaxe book that bangs or question marks are only allowed at the
end of method names. In fact:
class Test2
def weird?= val
end
end
fails with `SyntaxError` as well. What's baffling me is that
`attr_accessor`'s is capable of adding the method `weird?=`, which
can be verified calling `methods`:
t.methods => [... "weird?=" ...]
The method is there, only calling it causes the `SyntaxError`... Am I
missing something entirely obvious here?
-tim
I just stumbled across this weird behaviour and I'm puzzled that I've
not noticed it before. If I use `attr_accessor` to define a predicate
method, i.e. one ending in a question mark, the following happens:
class Test
attr_accessor :weird?
end
t = new Test
t.weird? => nil
t.weird?=true => SyntaxError: compile error
Which is only mildly confusing, considering it's implied somewhere in
the pickaxe book that bangs or question marks are only allowed at the
end of method names. In fact:
class Test2
def weird?= val
end
end
fails with `SyntaxError` as well. What's baffling me is that
`attr_accessor`'s is capable of adding the method `weird?=`, which
can be verified calling `methods`:
t.methods => [... "weird?=" ...]
The method is there, only calling it causes the `SyntaxError`... Am I
missing something entirely obvious here?
-tim