【文件属性】:
文件名称:method_pattern:Ruby方法的模式匹配
文件大小:10KB
文件格式:ZIP
更新时间:2021-05-14 10:59:30
Ruby
方法模式
Ruby方法的模式匹配
安装
将此行添加到您的应用程序的Gemfile中:
gem 'method_pattern'
然后执行:
$ bundle
或将其自己安装为:
$ gem install method_pattern
用法
扩展您希望能够与MethodPattern模块一起使用模式匹配的任何类:
class HandleResponse
extend MethodPattern
end
然后,您可以使用defn定义您的方法:
class HandleResponse
extend MethodPattern
defn :call do
# ...
end
end
在defn块中,使用with声明参数模式:
class Fibonnaci
extend MethodPattern
defn :call do
wit
【文件预览】:
method_pattern-master
----method_pattern.gemspec(908B)
----LICENSE.txt(1KB)
----lib()
--------method_pattern()
--------method_pattern.rb(2KB)
----Gemfile(169B)
----spec()
--------method_pattern_spec.rb(2KB)
--------spec_helper.rb(370B)
----Rakefile(117B)
----.travis.yml(88B)
----README.md(4KB)
----.rspec(53B)
----CODE_OF_CONDUCT.md(3KB)
----.gitignore(126B)
----bin()
--------console(349B)
--------setup(131B)