I’m try to create a generic anonymous class, and I want to set the
class name of the class, however I can’t find a function which allow me
to do this, the only way I can do this is actually assigner the newly
create class to a constant. the classname will be (in my case)
GenActRec::className.
Does someone know how to remove the “GenActRec::” ???
Does someone know is there another way to do this???
And useless #to_s awards. If anything, #to_str is somewhat useful to
get a type check, but coercing types with reckless abandon you’ll
shoot yourself in the foot when you least expect it.
I think we should have “useless use of #{}”-awards.
And useless #to_s awards. If anything, #to_str is somewhat useful to get
a type check, but coercing types with reckless abandon you’ll shoot
yourself in the foot when you least expect it.
On Thu, 12 Jan 2006 14:15:38 +0100, Christian N. [email protected] wrote:
And useless #to_s awards. If anything, #to_str is somewhat useful to
get a type check, but coercing types with reckless abandon you’ll
shoot yourself in the foot when you least expect it.
…except Symbol doesn’t have #to_str.
Oh, joy. Not like that matters in this specific case, but I can well
imagine that use. I guess it’s time to dig out the metaprogramming
helmets
to prevent severe trauma when banging heads against walls.
Oh, joy. Not like that matters in this specific case, but I can well imagine
that use. I guess it’s time to dig out the metaprogramming helmets to prevent
severe trauma when banging heads against walls.
it’s why i always use
“#{ obj }” # no useless after all
instead of obj.to_s or obj.to_str. it works - forget about it. same
goes for
Oh, joy. Not like that matters in this specific case, but I can well
imagine that use. I guess it’s time to dig out the metaprogramming
helmets to prevent severe trauma when banging heads against walls.
As far as I know, thats always equivalent to obj.to_s, which I think
is better looking:
class MyString
def to_s; “to_s called” end
def to_str; “to_str called” end
end
=> nil
my_string = MyString.new
=> to_s called
“#{my_string}”
=> “to_s called”
class MyString
undef to_s
end
=> nil
“#{my_string}”
NoMethodError: undefined method to_s' for #<MyString:0x31d59c> from /usr/local/lib/ruby/1.8/irb.rb:154:ininspect’
from /usr/local/lib/ruby/1.8/irb.rb:154:in eval_input' from /usr/local/lib/ruby/1.8/irb.rb:259:insignal_status’
from /usr/local/lib/ruby/1.8/irb.rb:147:in eval_input' from /usr/local/lib/ruby/1.8/irb/ruby-lex.rb:244:ineach_top_level_statement’
from /usr/local/lib/ruby/1.8/irb/ruby-lex.rb:230:in each_top_level_statement' from /usr/local/lib/ruby/1.8/irb/ruby-lex.rb:229:ineach_top_level_statement’
from /usr/local/lib/ruby/1.8/irb.rb:146:in eval_input' from /usr/local/lib/ruby/1.8/irb.rb:70:instart’
from /usr/local/lib/ruby/1.8/irb.rb:69:in `start’
from /usr/local/bin/irb:13
Maybe IRB bug!!
On Thu, 12 Jan 2006 17:48:35 +0100, Christian N. [email protected] wrote:
Sorry. I really wonder what I was thinking when I wrote that.
It has to be like that, of course:
Object.const_set(className.to_sym, genClass)
This allows for passing of strings and symbols. (And Fixnums, oh well.)
Hoolay! Look, mom, no type coercion! The little Java demons in the back
of
my skull cackle with glee at yet another potential obscure bug avoided.
(Happily ignoring any potential obscure bugs introduced, of course).
helmets to prevent severe trauma when banging heads against walls.
Sorry. I really wonder what I was thinking when I wrote that.
It has to be like that, of course:
Object.const_set(className.to_sym, genClass)
This allows for passing of strings and symbols. (And Fixnums, oh well.)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.