sd
Ruby
code posted
created at 08 Apr 17:02
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
class Router class Route attr_accessor :name,:path def initialize(name,path) @name = name @path = path end def to_s "#{@name}-->#{@path}" end end attr_accessor :routes def initialize(&block) @routes = [] instance_eval &block end def add(name,path) @routes << Route.new(name,path) end def default(path) @routes << Route.new(:root,path) end end router=Router.new do |r| add :ciao, '/ciao' add :hello, '/hello' default '/' end |
632 Bytes in 4 ms with coderay