【文件属性】:
文件名称:lawyer:Ruby 的强(鸭)类型
文件大小:68KB
文件格式:ZIP
更新时间:2021-07-12 11:57:18
Ruby
律师
Ruby 的强鸭打字。
Lawyer 允许您创建指定对象行为方式的合同。
require 'lawyer'
class Pingable < Lawyer :: Contract
confirm :ping
end
然后你可以确保你的类实现了契约:
require 'pingable'
class Foo
def ping
puts "ping"
end
def pong
puts "pong"
end
end
Foo . implements ( Pingable )
...但是当您编写松散耦合的对象然后定义它们之间的接口时,这种方法效果最好。 然后你可以编写规范来检查一个类是否实现了一个特定的契约:
require 'foo'
require 'pingable'
RSpec . describe Foo do
it {
【文件预览】:
lawyer-master
----LICENSE.txt(1KB)
----lib()
--------monkey_patch()
--------lawyer()
--------lawyer.rb(134B)
----Gemfile(91B)
----spec()
--------module_spec.rb(258B)
--------lib()
--------spec_helper.rb(187B)
----Rakefile(163B)
----lawyer.gemspec(835B)
----lawyer.jpg(59KB)
----README.md(3KB)
----.rspec(54B)
----.gitignore(154B)