Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have this problem too sometimes. It can even make me feel like I'm getting too clever for Ruby. I know that isn't the case. In reality, I think I'm just using the language in a non-ideal way.</p> <p>When I have a series of one line methods, which I find to be the ultimate conclusion to just about any object oriented refactor, I figure I have also locked in the design. This is probably a fine thing to do if the code has matured around the problem, but probably a bad thing to do prematurely. For that reason, I try to keep the methods a little more willy-nilly and with some meat on the bones.</p> <p>I also find, that when I have a series of one line methods, I'm probably getting closer to realizing one facet of the beauty of lisp. But Ruby simple doesn't seem like the right place to be doing that, I argue.</p> <p>So instead, I would prefer to be Ruby like. Well, what does that mean?</p> <p>I've seen a lot of people do this.</p> <pre><code>def is_pull_available?; false end </code></pre> <p>Knowing to leave off the second <code>;</code> is a sign of someone who is at least familiar with that aspect of the Ruby grammar.</p> <p>This is fast and easy to do, but still kinda yuk.</p> <p>So what's a Ruby programmar to do? One perhaps with a little extra free time? Well, maybe they can create a DSL. That's all they've really done so far anyway, might as well present it that much more elegantly.</p> <p>So perhaps we turn</p> <pre><code>def is_pull_available? false end </code></pre> <p>into </p> <pre><code>pull_available false </code></pre> <p>All you really need to do to make this happen is...</p> <pre><code>def self.pull_available(value) define_method(:is_pull_available?) { value } end </code></pre> <p>And either throw that in a base class or mix it in from a module.</p> <p>I think this is really a step you will want to reserve for when you really want to lock in the domain logic and accentuate it. The more you polish it up, the more you are going to feel poorly when it changes.</p> <p><a href="http://pragprog.com/book/ppmetr/metaprogramming-ruby" rel="nofollow">Metaprogramming in Ruby</a> is probably a great book to read if you are interested in this sorta stuff.</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