R
Ross Bamford
Hi folks.
I'm getting on really well with Ruby (I've not enjoyed programming this
much for ages ) but I've a few (probably simple) questions I'm hoping
you might be able to help with.
1) Is this the right way to define a method with a dynamic name?
eval <<-EOC
def #{method_name}
'You called #{method_name}'
end
EOC
it seems to(?) work, but I wonder if theres a better way?
2) I'm struggling with boolean attributes, and question marks.
attr_accessor (etc) won't allow me to pass those names in (I guess because
they're illegal instance var names). I tried:
attr_accessor :is_green
alias is_green? is_green
which works, but again it strikes me theres probably a better way that
I've missed.
3) Does this
class MyClass
@field = "one"
end
create a class or instance variable? And from that, does
class MyClass
@@field = "one"
end
create a class variable on MyClass, Class, or something else? I've tried a
few experiments and am more confused than when I started
4) And finally, not exactly a Ruby question, but relevant here I hope?
With a RubyGem, is it possible to install additional files besides
binaries? I'd like to install some manpages along with libs and bin. I
considered misusing the C extension build, but I don't know if it'd work
and it seems a bit nasty...
Thanks in advance!
I'm getting on really well with Ruby (I've not enjoyed programming this
much for ages ) but I've a few (probably simple) questions I'm hoping
you might be able to help with.
1) Is this the right way to define a method with a dynamic name?
eval <<-EOC
def #{method_name}
'You called #{method_name}'
end
EOC
it seems to(?) work, but I wonder if theres a better way?
2) I'm struggling with boolean attributes, and question marks.
attr_accessor (etc) won't allow me to pass those names in (I guess because
they're illegal instance var names). I tried:
attr_accessor :is_green
alias is_green? is_green
which works, but again it strikes me theres probably a better way that
I've missed.
3) Does this
class MyClass
@field = "one"
end
create a class or instance variable? And from that, does
class MyClass
@@field = "one"
end
create a class variable on MyClass, Class, or something else? I've tried a
few experiments and am more confused than when I started
4) And finally, not exactly a Ruby question, but relevant here I hope?
With a RubyGem, is it possible to install additional files besides
binaries? I'd like to install some manpages along with libs and bin. I
considered misusing the C extension build, but I don't know if it'd work
and it seems a bit nasty...
Thanks in advance!