Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Why Best Practices?

jeg2
August 04, 2013

Why Best Practices?

This is JEG2's segment of the Ruby Rogues panel form LSRC 2013.

jeg2

August 04, 2013
Tweet

More Decks by jeg2

Other Decks in Technology

Transcript

  1. I Only Have Time to Make One Point The others

    made me include this slide!
  2. .

  3. How Should We Use Struct? class Specialized < Struct.new(:whatever) #

    ... define custom methods here... end Specialized = Struct.new(:whatever) do # ... define custom methods here... end
  4. Code Similarity and Malleability Specialized = Struct.new(:whatever) do # ...

    define custom methods here... end Trivial = Struct.new(:whatever)
  5. An Extra Class • The anonymous class doesn’t tell us

    much • Code reloading may cause “TypeError: superclass mismatch…” [Specialized, #<Class:0x007f8ba7389d18>, Struct, Enumerable, Object, PP::ObjectMixin, Kernel, BasicObject] class Specialized < Struct.new(:whatever) # ... define custom methods here... end
  6. The “super” Problem class Specialized < Struct.new(:whatever) def whatever super

    || :default end include SomeMixin end Specialized = Struct.new(:whatever) do def whatever self[:whatever] || :default end prepend SomeMixin end
  7. The Point • It’s not about the one right way

    to code • It’s about what we learn in the discussion • This trivial example alone includes: • Code malleability • The ancestor class chain • The value of prepend