Slide 1

Slide 1 text

I Only Have Time to Make One Point The others made me include this slide!

Slide 2

Slide 2 text

.

Slide 3

Slide 3 text

Thanks!

Slide 4

Slide 4 text

Why Best Practices?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

I Prefer the Block Form But that’s not the point!

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

An Extra Class • The anonymous class doesn’t tell us much • Code reloading may cause “TypeError: superclass mismatch…” [Specialized, #, Struct, Enumerable, Object, PP::ObjectMixin, Kernel, BasicObject] class Specialized < Struct.new(:whatever) # ... define custom methods here... end

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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