Permalink
Browse files

Added usage examples

  • Loading branch information...
1 parent f042811 commit 13d11c015e712fb6a7923394b39e4b4c6f19f38b @fredwu committed Sep 11, 2012
Showing with 49 additions and 3 deletions.
  1. +49 −1 README.md
  2. +0 −2 spec/ruby_decorators_spec.rb
View
@@ -19,7 +19,55 @@ Or install it yourself as:
## Usage
```ruby
- # TODO
+class Batman < RubyDecorator
+ def call(this)
+ this.sub('world', 'batman')
+ end
+end
+
+class Catwoman < RubyDecorator
+ def initialize(*args)
+ @args = args.any? ? args : ['catwoman']
+ end
+
+ def call(this)
+ this.sub('world', @args.join(' '))
+ end
+end
+
+class DummyClass
+ extend RubyDecorators
+
+ def initialize
+ @greeting = 'hello world'
+ end
+
+ def hello_world
+ @greeting
+ end
+
+ +Batman
+ def hello_batman
+ @greeting
+ end
+
+ +Catwoman
+ def hello_catwoman
+ @greeting
+ end
+
+ +Catwoman.new('super', 'catwoman')
+ def hello_super_catwoman
+ @greeting
+ end
+end
+
+dummy = DummyClass.new
+
+dummy.hello_world # => "hello world"
+dummy.hello_batman # => "hello batman"
+dummy.hello_catwoman # => "hello catwoman"
+dummy.hello_super_catwoman # => "hello super catwoman"
```
## License
@@ -26,8 +26,6 @@ def call(this)
class DummyClass
extend RubyDecorators
- attr_reader :greeting
-
def initialize
@greeting = 'hello world'
end

0 comments on commit 13d11c0

Please sign in to comment.