1. 3

    Why is it not “DCI” when one simply uses composition to access the data objects?

    1. 3

      Agree. I don’t “get” DCI. It seems like overkill crazytown.

      1. 1

        Especially because you can use them to achieve the entire effect without these crazy negatives.

      1. 2

        There seemed to be a distinct lack of a “fireside” in this chat.

        1. 4

          I think it’s a neat idea, but your last paragraph seems like the killer problem. If the linked-to sites are OK with it, it seems fine (IMO). But figuring out if it’s OK or not sounds like a hard problem.

          1. 1

            Yay! I think we have a PR for supporting JSON types natively in Rails. I’m really excited about PostgreSQL 9.2!

            1. 9

              Another Pro Tip™, you can use define_method inside the Class.new block to create another closure. This gives the method access to variables defined outside the Class.new:

              bar = :hello
              
              z = Class.new {
                define_method(:omg) { bar }
              }
              
              z.new.omg # => :hello
              

              I find it to be another handy trick for defining simple mocks.

              1. 4

                I should just ping you every time I wrote one of these. :)

                1. 5

                  I suppose, but then how would I earn this sweet sweet lobster karma? ;–)

                  1. 2

                    Mmm, imaginary internet points… drools

              1. 2

                I always thought it was odd that a Ruby object can call another object’s protected methods if they are of the same class, mostly because I couldn’t think of a circumstance where this would be a desirable behavior. The example in the article of using this behavior while implementing equality operators is something I hadn’t thought of.

                1. 3

                  That’s pretty much the only use case I can think of. Even then, I implement equality operators so infrequently that I’ll forget!

                  1. 3

                    It’s useful for any kind of comparison (<, >, <=>, ==, ===). I only use protected for methods that are used in comparison (most commonly, accessors).

                  1. 3

                    I like the smiley face in the code example

                    1. 2

                      Fucking Wordpress, man.

                      Also, your suggestion about a block to Struct.new made it into this version, thanks for that. :)

                      1. 1

                        That blog is in desperate need of a new theme.

                    1. 7

                      Nice. You can also give Struct.new a block and define instance methods:

                      irb(main):002:0> Struct.new('Foo', :bar) do
                      irb(main):003:1*   def baz; :omg; end
                      irb(main):004:1> end
                      => Struct::Foo
                      irb(main):005:0> Struct::Foo.new.baz
                      => :omg
                      irb(main):006:0>
                      
                      1. 1

                        Thanks! Super neat. :)