Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create your own module/library which you include into scope when you need it to perform this task. </p> <p>Such as "requre 'unitCoversions' " </p> <p>And Chances are, somebody has already done this if you look hard enough :)</p> <p>However <em>DONT</em> try modifying the native core class, that will only end in Misery. </p> <p>( Also, the class you want to extend is 'numeric' , that will apply to both Integers and Floats :) ) </p> <blockquote> <p>Not entirely clear why I shouldn't do this... Rails does this to the string class to great success. </p> </blockquote> <p>Because it <em>can</em> be done doesn't mean it <em>should</em> be done. 'Monkey Patching' as it is known can have all sorts of odd side effects, and they can be an epic failure when done wrong. </p> <p>Do it when there is no good alternative. </p> <p>Because if you really wanted to do something daft, you could build an entire framework that <em>ALL</em> it did was monkey patch the core classes. </p> <p>Just for example, flip databasing on its head. </p> <pre><code>5.getArtist(); 10.getEvent(); 100.getTrack(); </code></pre> <p>etc etc. there is no limit to how many bad ways there are to do that. </p> <pre><code>"Bob".createUser(); </code></pre> <p>misery in a cup. </p> <p>If you want to do something practical, have a Convert class or function, </p> <pre><code>convert( 3 , { :from=&gt;:miles, :to=&gt;:meters }); </code></pre> <p>at least you're not polluting the global namespace and core functions that way and it makes more coherent sense. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload