Hello World

Get Version

1.0.2

→ ‘contextr

Hello World for ContextR

example do
  class MyApplication
    def greet
      "Hello, World"
    end
  end

  app = MyApplication.new
  assert_equal "Hello, World", app.greet
end

And what about request coming from down under? Let’s introduce Localization.

example do
  class MyApplication
    in_layer :au do
      def greet
        "G'day, mate"
      end
    end
  end

  app = MyApplication.new

  assert_equal "Hello, World", app.greet

  ContextR::with_layer :au do
    assert_equal "G'day, mate", app.greet
  end
end

And what if down under changed its habbits? Let’s redefine it.

example do
  class MyApplication
    in_layer :au do
      def greet
        super + " and God Save the Queen"
      end
    end
  end

  app = MyApplication.new

  assert_equal "Hello, World", app.greet

  ContextR::with_layer :au do
    assert_equal "Hello, World and God Save the Queen", app.greet
  end
end

The key here is, that the method greet method in the :au layer is redefined and no new method is added.

example do
  class MyApplication
    in_layer :au do
      $inner_module_1 = self
    end
  end
  class MyApplication
    in_layer :au do
      $inner_module_2 = self
    end
  end

  assert(($inner_module_1 == $inner_module_2), "Modules should be equal")
end

28th April 2008
Theme extended from Paul Battley