Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is it that you can do `Integer('1')` in Ruby?

Tags:

ruby

How does the standard library allow you to coerce a String into an Integer with Integer('1') #=> 1? Is there a language feature that allows one to create this kind of conversion syntax in a class?

like image 534
1ijk Avatar asked Aug 05 '26 00:08

1ijk


1 Answers

It's not a class, just a method in disguise.

like image 197
steenslag Avatar answered Aug 06 '26 14:08

steenslag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!