Simple method annotations like in java or Python methods decorators
Install it yourself as:
$ gem install carioca
require 'rubygems'
require 'simple-annotations'
class A
using AnnotationRefinement
annotate!
§test 'string'
def method
return annotations(__callee__)
end
end
anA = A.new
pp anA.method
Display
{:test=>"string"}
require 'rubygems'
require 'simple-annotations'
class A
using AnnotationRefinement
annotate!
§foobar {:color => 'cyan' } # Hash
§test 1234 # Numeric
§foobar color: 'cyan' # Hash by double splat, like keyword
§testbar 10, {}, [], 'string' # Hybrid by splat
§barfoo # Boolean set true
§footest 'string' # String
def method
[...]
end
end
pp A.annotations[:method]
Display
{:test=>1234, :foobar=>{:color=>"cyan"}, :testbar=>[10, {}, [], "string"], :barfoo=>true, :footest=>"string"}
Supporting 2 Hooks :
- §after
- §before
Like :
require 'rubygems'
require 'simple-annotations'
class A
using AnnotationRefinement
annotate!
§after -> { puts 'after' }
§before -> { puts 'before' }
def m1
puts 'test'
end
end
anA = A.new
anA.m1
Display
before
test
after