vendredi 31 juillet 2015

How does forwardable work in this context?

I'm following along a tutorial to make a Rack-based app:

require 'forwardable'
module Eldr
  class App
    class << self
      extend Forwardable
      attr_accessor :builder
      def_delegators :builder, :map, :use

      def builder
        @builder ||= Rack::Builder.new
      end
    end
  end
end

I know this will sound really noobish, but I'm new to Ruby metaprogramming:

  • What exactly is the class << self? Doesnt that mean App < App?
  • What exactly is Forwardable? I looked it up but I'm sad to say I don't understand it still
  • Why is app extending Forwardable and what is Forwardable?

I know that the goal is to make this bit behave like Rack::Builder; Just trying to wrap my head around this one.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire