summaryrefslogtreecommitdiff
path: root/ext/fiddle/lib/fiddle/function.rb
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2021-02-26 09:57:13 -0800
committerAaron Patterson <tenderlove@ruby-lang.org>2021-02-26 09:57:13 -0800
commit0590e9b677e8c0b7a2364f660f06d9f5bd8fe87d (patch)
tree327bdb14b684b627d41678ce30d9e2db0da37a64 /ext/fiddle/lib/fiddle/function.rb
parentcfc23903df6bde6d79292d8a0291bc82e920b54e (diff)
Fiddle::Function responds to to_proc
This lets us cast a Fiddle::Function to a block, allowing is to write things like: ```ruby f = Fiddle::Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP) define_method :strcpy, &f ```
Diffstat (limited to 'ext/fiddle/lib/fiddle/function.rb')
-rw-r--r--ext/fiddle/lib/fiddle/function.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/ext/fiddle/lib/fiddle/function.rb b/ext/fiddle/lib/fiddle/function.rb
index 0f9913adeb..f9910a0524 100644
--- a/ext/fiddle/lib/fiddle/function.rb
+++ b/ext/fiddle/lib/fiddle/function.rb
@@ -19,5 +19,10 @@ module Fiddle
def to_i
ptr.to_i
end
+
+ # Turn this function in to a proc
+ def to_proc
+ lambda { |*args| self.call(*args) }
+ end
end
end