Ruby 2.4参考手册
Fiddle
Fiddle::Closure::BlockCaller
Parent:Fiddle::Closure
扩展Fiddle :: Closure,以允许在一个块中构建闭包
公共类方法
new(ctype, args, abi = Fiddle::Function::DEFAULT, &block) Show source
描述
构建一个新的BlockCaller对象。
-
ctype
是要返回的C类型
-
args
已通过回调
-
abi
是关闭的abi
如果在准备ffi_cif或ffi_prep_closure时出错,则会引发RuntimeError。
例
include Fiddle
cb = Closure::BlockCaller.new(TYPE_INT, [TYPE_INT]) do |one|
one
end
func = Function.new(cb, [TYPE_INT], TYPE_INT)
调用超类方法Fiddle :: Closure.new
# File ext/fiddle/lib/fiddle/closure.rb, line 34
def initialize ctype, args, abi = Fiddle::Function::DEFAULT, &block
super(ctype, args, abi)
@block = block
end
公共实例方法
call(*args) Show source
用args调用构造的BlockCaller
例如see :: new
# File ext/fiddle/lib/fiddle/closure.rb, line 43
def call *args
@block.call(*args)
end
Fiddle相关
Ruby 是一种面向对象、命令式、函数式、动态的通用编程语言,是世界上最优美而巧妙的语言。
主页 | https://www.ruby-lang.org/ |
源码 | https://github.com/ruby/ruby |
版本 | 2.4 |
发布版本 | 2.4.1 |