Can a plain Ruby object instance return a primitive? -


how can define class instance without method call returns string representation of itself, without instance.to_s or similar being called?

is there method defines native return instance when invoked without method, can strip object handling , return primitive?

the same way string behaves:

>> str=string.new('abc') >> s "abc" 

str doesn't return

#<string abc> 

or it, , it, console extracting value?

how can make class('abc') same thing class.new('abc') string? sub-classing string option, i'd know alternatives.

if enter following in irb should see expected result:

class foo   def inspect     "foo"   end end  foo.new #> "foo" 

but how displayed. i'm not sure want achieve.

creating string

s = string.new('abc') 

is constructing 2 strings: 1 literal 'abc' , 1 call new, pointless unless want create duplicate.

perhaps if tell bit more want achieve can better answer.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -