repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/grouped_input.rb | lib/active_interaction/grouped_input.rb | # frozen_string_literal: true
module ActiveInteraction
# Holds a group of inputs together for passing from {Base} to {Filter}s.
#
# @private
class GroupedInput
include Comparable
attr_reader :data
protected :data
def initialize(**data)
@data = data
end
def [](key)
@data[k... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/hash_input.rb | lib/active_interaction/hash_input.rb | # frozen_string_literal: true
module ActiveInteraction
# Represents a processed hash input.
class HashInput < Input
# @private
def initialize(filter, value: nil, error: nil, children: {})
super(filter, value: value, error: error)
@children = children
end
# @overload children
# C... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/inputs.rb | lib/active_interaction/inputs.rb | # frozen_string_literal: true
require 'forwardable'
module ActiveInteraction
# Holds inputs passed to the interaction.
class Inputs
include Enumerable
extend Forwardable
# matches inputs like "key(1i)"
GROUPED_INPUT_PATTERN = /
\A
(?<key>.+) # extracts "key"
\((?<index>\... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/concerns/missable.rb | lib/active_interaction/concerns/missable.rb | # frozen_string_literal: true
module ActiveInteraction
# Handle common `method_missing` functionality.
#
# @private
module Missable
extend ActiveSupport::Concern
private
# @param slug [Symbol]
#
# @yield [klass, args, options]
#
# @yieldparam klass [Class]
# @yieldparam args [... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/concerns/hashable.rb | lib/active_interaction/concerns/hashable.rb | # frozen_string_literal: true
module ActiveInteraction
# Allow `hash` to be overridden when given arguments and/or a block.
#
# @private
module Hashable
extend ActiveSupport::Concern
def hash(*args, &block)
if args.empty? && !block_given?
super
else
method_missing(:hash, *a... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/concerns/runnable.rb | lib/active_interaction/concerns/runnable.rb | # frozen_string_literal: true
module ActiveInteraction
# @abstract Include and override {#execute} to implement a custom Runnable
# class.
#
# @note Must be included after `ActiveModel::Validations`.
#
# Runs code and provides the result.
#
# @private
module Runnable
extend ActiveSupport::Conce... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/concerns/active_recordable.rb | lib/active_interaction/concerns/active_recordable.rb | # frozen_string_literal: true
module ActiveInteraction
# Implement the minimal ActiveRecord interface.
#
# @private
module ActiveRecordable
# Returns the column object for the named filter.
#
# @param name [Symbol] The name of a filter.
#
# @example
# class Interaction < ActiveInterac... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/concerns/active_modelable.rb | lib/active_interaction/concerns/active_modelable.rb | # frozen_string_literal: true
module ActiveInteraction
# Implement the minimal ActiveModel interface.
#
# @private
module ActiveModelable
extend ActiveSupport::Concern
include ActiveModel::Conversion
include ActiveModel::Validations
extend ActiveModel::Naming
# @return (see ClassMethods#... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filter/error.rb | lib/active_interaction/filter/error.rb | # frozen_string_literal: true
require 'active_support/inflector'
module ActiveInteraction
class Filter
# A validation error that occurs while processing the filter.
class Error
# @private
def initialize(filter, type, name: nil)
@filter = filter
@name = name || filter.name
... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filter/column.rb | lib/active_interaction/filter/column.rb | # frozen_string_literal: true
module ActiveInteraction
class Filter
# A minimal implementation of an `ActiveRecord::ConnectionAdapters::Column`.
class Column
# @return [nil]
attr_reader :limit
# @return [Symbol]
attr_reader :type
class << self
# Find or create the `Fil... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/string_filter.rb | lib/active_interaction/filters/string_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.string(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are Strings.
#
# @!macro filter_method_params
... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/abstract_numeric_filter.rb | lib/active_interaction/filters/abstract_numeric_filter.rb | # frozen_string_literal: true
module ActiveInteraction
# @abstract
#
# Common logic for filters that handle numeric objects.
#
# @private
class AbstractNumericFilter < Filter
def database_column_type
self.class.slug
end
private
def matches?(value)
value.is_a?(klass)
rescue... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/float_filter.rb | lib/active_interaction/filters/float_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.float(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are Floats. Integer and String values are converted
# ... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/abstract_date_time_filter.rb | lib/active_interaction/filters/abstract_date_time_filter.rb | # frozen_string_literal: true
module ActiveInteraction
# @abstract
#
# Common logic for filters that handle `Date`, `DateTime`, and `Time`
# objects.
#
# @private
class AbstractDateTimeFilter < Filter
def database_column_type
self.class.slug
end
def accepts_grouped_inputs?
true... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/date_time_filter.rb | lib/active_interaction/filters/date_time_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.date_time(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are DateTimes. String values are processed using
# ... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/boolean_filter.rb | lib/active_interaction/filters/boolean_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.boolean(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are Booleans. The strings `"1"`, `"true"`, and `"on"`
... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/time_filter.rb | lib/active_interaction/filters/time_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.time(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are Times. Numeric values are processed using `at`.
# ... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/array_filter.rb | lib/active_interaction/filters/array_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.array(*attributes, options = {}, &block)
# Creates accessors for the attributes and ensures that values passed to
# the attributes are Arrays.
#
# @!macro filter_method_para... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/hash_filter.rb | lib/active_interaction/filters/hash_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.hash(*attributes, options = {}, &block)
# Creates accessors for the attributes and ensures that values passed to
# the attributes are Hashes.
#
# @!macro filter_method_param... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/decimal_filter.rb | lib/active_interaction/filters/decimal_filter.rb | # frozen_string_literal: true
require 'bigdecimal'
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.decimal(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are BigDecimals. Numerics and String... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/integer_filter.rb | lib/active_interaction/filters/integer_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.integer(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are Integers. String values are converted into
# I... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/object_filter.rb | lib/active_interaction/filters/object_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.object(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are the correct class.
#
# @!macro filter_method_... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/record_filter.rb | lib/active_interaction/filters/record_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.record(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are the correct class. Blank strings passed in will be
... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/interface_filter.rb | lib/active_interaction/filters/interface_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.interface(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes implement an interface. An interface can be based on a
... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/file_filter.rb | lib/active_interaction/filters/file_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.file(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes respond to the `rewind` method. This is useful when
# pas... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/symbol_filter.rb | lib/active_interaction/filters/symbol_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.symbol(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are Symbols. Strings will be converted to Symbols.
#
... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/filters/date_filter.rb | lib/active_interaction/filters/date_filter.rb | # frozen_string_literal: true
module ActiveInteraction
class Base # rubocop:disable Lint/EmptyClass
# @!method self.date(*attributes, options = {})
# Creates accessors for the attributes and ensures that values passed to
# the attributes are Dates. String values are processed using `parse`
# ... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
AaronLasseigne/active_interaction | https://github.com/AaronLasseigne/active_interaction/blob/97667c8283a4479c7ffc021be31f168d17b20b72/lib/active_interaction/modules/validation.rb | lib/active_interaction/modules/validation.rb | # frozen_string_literal: true
module ActiveInteraction
# Validates inputs using filters.
#
# @private
module Validation
class << self
# @param context [Base]
# @param filters [Hash{Symbol => Filter}]
# @param inputs [Inputs]
def validate(context, filters, inputs)
filters.eac... | ruby | MIT | 97667c8283a4479c7ffc021be31f168d17b20b72 | 2026-01-04T15:57:54.678054Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/rakelib/types_generator.rb | rakelib/types_generator.rb | require 'tempfile'
module FFI
# @private
class TypesGenerator
##
# Maps different C types to the C type representations we use
TYPE_MAP = {
"char" => :char,
"signed char" => :char,
"__signed char" => :char,
"unsigned char" => :uchar,
"short" => ... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/rakelib/ffi_gem_helper.rb | rakelib/ffi_gem_helper.rb | require 'bundler'
require 'bundler/gem_helper'
class FfiGemHelper < Bundler::GemHelper
attr_accessor :cross_platforms
def install
super
task "release:guard_clean" => ["release:update_history"]
task "release:update_history" do
update_history
end
task "release:rubygem_push" => ["gem:nat... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_closure_IrV.rb | bench/bench_closure_IrV.rb | require_relative 'bench_helper'
module BenchClosureIrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
callback :closureVrV, [ ], :void
attach_function :ffi_bench, :testClosureIrV, [ :closureVrV, :int ], :void
def self.rb_bench(i, &block); nil; end
end
puts "Benchmark [ ], :void clos... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_struct.rb | bench/bench_struct.rb | require_relative 'bench_helper'
module BenchStruct
module StructBench
extend FFI::Library
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_s32_v, [ :int ], :void
begin
attach_function :bench_struct_in, :ptr_ret_int32_t, [ :buffer_in, :int ], :void
rescue FFI::NotFoundErro... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_struct_field.rb | bench/bench_struct_field.rb | require_relative 'bench_helper'
module BenchStructField
iter = ITER
class TestStruct < FFI::Struct
layout :i, :int, :p, :pointer
end
s = TestStruct.new(FFI::MemoryPointer.new(TestStruct))
puts "Benchmark FFI Struct.get(:int) performance, #{iter}x"
10.times {
puts Benchmark.measure {
i = 0; ... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_PrV.rb | bench/bench_PrV.rb | require_relative 'bench_helper'
module BenchPrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench, :bench_P_v, [ :buffer_in ], :void, :save_errno => false
end
puts "Benchmark [ :buffer_in ], :void performance (pre allocated pointer), #{ITER}x calls"
ptr = FFI::Memory... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_closure_VrV.rb | bench/bench_closure_VrV.rb | require_relative 'bench_helper'
module BenchClosureVrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
callback :closureVrV, [ ], :void
attach_function :ffi_bench, :testClosureVrV, [ :closureVrV ], :void
@blocking = true
attach_function :threaded_bench, :testThreadedClosureVrV, [ :cl... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_VrV.rb | bench/bench_VrV.rb | require_relative 'bench_helper'
module BenchVrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, :returnVoid, [ ], :void
attach_function :ffi_bench_noerrno, :returnVoid, [ ], :void, :save_errno => false
def self.rb_bench; nil; end
end
puts "Benchmark [ ], :... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_IIIIIIrV.rb | bench/bench_IIIIIIrV.rb | require_relative 'bench_helper'
module BenchIIIIIIrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, 'bench_s32s32s32s32s32s32_v', [ :int, :int, :int, :int, :int, :int ], :void, :save_errno => false
def self.rb_bench(i0, i1, i2, i3, i4, i5); nil; end
end
puts ... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_getlogin.rb | bench/bench_getlogin.rb | require_relative 'bench_helper'
require 'etc'
module BenchGetlogin
iter = ITER
module Posix
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :getlogin, [], :string
end
# getlogin(2) might return NULL, in which case Etc.getlogin uses ENV["USER"].
# This should not matter for this b... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_buffer_fill.rb | bench/bench_buffer_fill.rb | require_relative 'bench_helper'
module BenchBufferFill
iter = ITER
puts "Benchmark Buffer#put_array_of_float performance, #{iter}x"
5.times {
ptr = FFI::Buffer.new(:float, 8, false)
puts Benchmark.measure {
iter.times {
ptr.put_array_of_float(0, [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 ])... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_PPrV.rb | bench/bench_PPrV.rb | require_relative 'bench_helper'
module BenchPPrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench, :bench_PP_v, [ :buffer_in, :buffer_in ], :void
end
puts "Benchmark [ :buffer_in, :pointer ], :void performance, #{ITER}x calls"
ptr = FFI::MemoryPointer.new :int
10.... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_strlen.rb | bench/bench_strlen.rb | require_relative 'bench_helper'
module BenchStrlen
module LibC
extend FFI::Library
ffi_lib 'c'
attach_function :strlen, [ :string ], :int
end
if LibC.strlen("test") != 4
raise ArgumentError, "FFI.strlen returned incorrect value"
end
puts "Benchmark FFI api strlen(3) performance, #{ITER}x"
... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_enum_i.rb | bench/bench_enum_i.rb | require_relative 'bench_helper'
module BenchEnumI
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
enum :foo, [ :a, :b, :c ]
attach_function :ffi_bench, :bench_s32_v, [ :foo ], :void, :save_errno => true
attach_function :ffi_bench_i, :bench_s32_v, [ :int ], :void, :save_errno => true
d... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_IIIrV.rb | bench/bench_IIIrV.rb | require_relative 'bench_helper'
module BenchIIIrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, :bench_s32s32s32_v, [ :int, :int, :int ], :void, :save_errno => false
def self.rb_bench(i0, i1, i2); nil; end
end
puts "Benchmark [ :int, :int, :int ], :void perf... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_VrI.rb | bench/bench_VrI.rb | require_relative 'bench_helper'
module BenchVrI
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, :returnInt, [ ], :int, :save_errno => false
def self.rb_bench; 0xdeadbeef; end
end
puts "Benchmark [ ], :int performance, #{ITER}x calls"
10.times {
puts Benc... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_memptr_fill.rb | bench/bench_memptr_fill.rb | require_relative 'bench_helper'
module BenchMemptrFill
iter = ITER
puts "Benchmark MemoryPointer#put_array_of_float performance, #{iter}x"
5.times {
ptr = FFI::MemoryPointer.new(:float, 8, false)
puts Benchmark.measure {
iter.times {
ptr.put_array_of_float(0, [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_enum.rb | bench/bench_enum.rb | require_relative 'bench_helper'
module BenchEnum
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
enum :foo, [ :a, :b, :c ]
attach_function :ffi_bench, :bench_s32_v, [ :foo ], :void, :save_errno => false
attach_function :ffi_bench_i, :bench_s32_v, [ :int ], :void, :save_errno => false
... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_chmod.rb | bench/bench_chmod.rb | require_relative 'bench_helper'
module BenchChmod
iter = ITER
file = "README"
module Posix
extend FFI::Library
ffi_lib FFI::Library::LIBC
def self.chmod(mode, path)
if self._chmod(path, mode) != 0
end
end
if FFI::Platform.windows?
attach_function :_chmod, :_chmod, [ :strin... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_helper.rb | bench/bench_helper.rb | require 'benchmark'
require 'rbconfig'
lib = File.expand_path('../../lib', __FILE__)
cext = "#{lib}/ffi_c.#{RbConfig::CONFIG['DLEXT']}"
if (RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx') && !File.exist?(cext)
abort "#{cext} is not compiled. Compile it with 'rake compile' first."
end
$LOAD_PATH.unshift(lib)
require... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_gettimeofday.rb | bench/bench_gettimeofday.rb | require_relative 'bench_helper'
module BenchGettimeofday
module Posix
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :gettimeofday, [ :buffer_out, :pointer ], :int
end
class Timeval < FFI::Struct
layout :tv_sec, :ulong, :tv_nsec, :ulong
end
iter = ITER
puts "Benchmark FFI ... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_buffer_alloc.rb | bench/bench_buffer_alloc.rb | require_relative 'bench_helper'
module BenchBufferAlloc
iter = ITER
puts "Benchmark Buffer.new(:int, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
i = 0; while i < iter
FFI::Buffer.new(:int, 1, true)
i += 1
end
}
}
puts "Benchmark Buffer.alloc_out(... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_LLLrV.rb | bench/bench_LLLrV.rb | require_relative 'bench_helper'
module BenchLLLrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_s64s64s64_v, [ :long_long, :long_long, :long_long ], :void, :save_errno => false
end
puts "Benchmark [ :long_long, :long_long, :long_long ], :void performance, #{ITER}x c... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_autoptr.rb | bench/bench_autoptr.rb | require_relative 'bench_helper'
module BenchAutoptr
iter = ITER
class Ptr < FFI::AutoPointer
def self.release(ptr)
LibC.free(ptr);
end
end
module LibC
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :malloc, [ :long ], Ptr, :ignore_error => true
attach_function :m... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_SrV.rb | bench/bench_SrV.rb | require_relative 'bench_helper'
module BenchSrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_S_v, [ :string ], :void
end
puts "Benchmark [ :string ], :void performance, #{ITER}x calls"
s = 'a' * 1000
10.times {
puts Benchmark.measure {
ITER.times { Li... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_math.rb | bench/bench_math.rb | require_relative 'bench_helper'
module BenchMath
module FFIMath
extend FFI::Library
ffi_lib FFI::Platform.windows? ? FFI::Library::LIBC : 'm'
attach_function :cos, [ :double ], :double
attach_function :cosf, [ :float ], :float
end
if FFIMath.cos(0) != 1
raise ArgumentError, "FFI.cos returned ... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_struct_size.rb | bench/bench_struct_size.rb | require_relative 'bench_helper'
module BenchStructSize
iter = ITER
layout = class TestStruct < FFI::Struct
layout :i, :int, :p, :pointer
end
puts "Benchmark FFI Struct class size performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { TestStruct.size }
}
}
s = TestStr... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_IrV.rb | bench/bench_IrV.rb | require_relative 'bench_helper'
module BenchIrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, :bench_s32_v, [ :int ], :void, :save_errno => false
def self.rb_bench(i0); nil; end
end
puts "Benchmark [ :int ], :void performance, #{ITER}x calls"
10.times {
... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_PPPrV.rb | bench/bench_PPPrV.rb | require_relative 'bench_helper'
module BenchPPPrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_ptr, :bench_PPP_v, [ :pointer, :pointer, :pointer ], :void, :save_errno => false
attach_function :bench_buffer, :bench_PPP_v, [ :pointer, :pointer, :pointer ], :void, :sav... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_closure_IIIrV.rb | bench/bench_closure_IIIrV.rb | require_relative 'bench_helper'
module BenchClosureIIIrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
callback :closureIIIrV, [ :int, :int, :int ], :void
attach_function :ffi_bench, :testClosureIIIrV, [ :closureIIIrV, :int, :int, :int ], :void
def self.rb_bench(a, b, c, &block); yield(... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_getpid.rb | bench/bench_getpid.rb | require_relative 'bench_helper'
module BenchGetpid
iter = ITER
module Posix
extend FFI::Library
ffi_lib 'c'
if FFI::Platform.windows?
attach_function :getpid, :_getpid, [], :uint, :save_errno => false
else
attach_function :getpid, [], :uint, :save_errno => false
end
end
puts ... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_umask.rb | bench/bench_umask.rb | require_relative 'bench_helper'
module BenchUmask
module Posix
extend FFI::Library
ffi_lib 'c'
attach_function 'umask', [ :int ], :int
end
module NativeFile
extend FFI::Library
ffi_lib 'c'
# Attaching the function to this module is about 10% faster than calling Posix.umask
if FFI::Pla... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_buffer.rb | bench/bench_buffer.rb | require_relative 'bench_helper'
module BenchBuffer
iter = ITER
module BufferBench
extend FFI::Library
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_s32_v, [ :int ], :void
begin
attach_function :bench_buffer_in, :ptr_ret_int32_t, [ :buffer_in, :int ], :void
rescue FF... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_FrV.rb | bench/bench_FrV.rb | require_relative 'bench_helper'
module BenchFrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_f32_v, [ :float ], :void
def self.rb_bench(i0); nil; end
end
puts "Benchmark [ :float ], :void performance, #{ITER}x calls"
f = 1.0
10.times {
puts Benchmark.me... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_memptr_alloc.rb | bench/bench_memptr_alloc.rb | require_relative 'bench_helper'
module BenchMemptrAlloc
iter = ITER
module LibC
extend FFI::Library
ffi_lib 'c'
attach_function :calloc, [ :size_t, :size_t ], :pointer, :save_errno => false
attach_function :free, [ :pointer ], :void, :save_errno => false
end
puts "Benchmark calloc(1, 4) perfo... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_IIIrI.rb | bench/bench_IIIrI.rb | require_relative 'bench_helper'
module BenchIIIrI
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench, :bench_s32s32s32_v, [ :int, :int, :int ], :int
end
puts "Benchmark [ :int, :int, :int ], :int performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_FFFrV.rb | bench/bench_FFFrV.rb | require_relative 'bench_helper'
module BenchFFFrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_f32f32f32_v, [ :float, :float, :float ], :void
def self.rb_bench(a0, a1, a2); nil; end
end
puts "Benchmark [ :float, :float, :float ], :void performance, #{ITER}x cal... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_getuid.rb | bench/bench_getuid.rb | require_relative 'bench_helper'
module BenchGetuid
iter = ITER
module Posix
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :getuid, [], :uint
end
puts "uid=#{Process.pid} Posix.getuid=#{Posix.getuid}"
puts "Benchmark FFI getuid performance, #{iter}x calls"
10.times {
puts... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/bench/bench_time.rb | bench/bench_time.rb | require_relative 'bench_helper'
module BenchTime
module Posix
extend FFI::Library
ffi_lib FFI::Library::LIBC
if FFI::Library::LIBC =~ /ucrtbase/
attach_function :time, :_time64, [ :buffer_out ], :uint64, ignore_error: true
else
attach_function :time, [ :buffer_out ], :ulong, ignore_error:... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/samples/getlogin.rb | samples/getlogin.rb | require 'ffi'
module Foo
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :getlogin, [ ], :string
end
puts "getlogin=#{Foo.getlogin}"
| ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/samples/hello.rb | samples/hello.rb | require 'ffi'
module Foo
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function("cputs", "puts", [ :string ], :int)
end
Foo.cputs("Hello, World via libc puts using FFI on MRI ruby")
| ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/samples/qsort.rb | samples/qsort.rb | require 'ffi'
module LibC
extend FFI::Library
ffi_lib FFI::Library::LIBC
callback :qsort_cmp, [ :pointer, :pointer ], :int
attach_function :qsort, [ :pointer, :ulong, :ulong, :qsort_cmp ], :int
end
p = FFI::MemoryPointer.new(:int, 2)
p.put_array_of_int32(0, [ 2, 1 ])
puts "ptr=#{p.inspect}"
puts "Before qsort... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/samples/getpid.rb | samples/getpid.rb | require 'ffi'
module Foo
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :getpid, [ ], :int
end
puts "My pid=#{Foo.getpid}"
| ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/samples/pty.rb | samples/pty.rb | require 'ffi'
module PTY
private
module LibC
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :forkpty, [ :buffer_out, :buffer_out, :buffer_in, :buffer_in ], :int
attach_function :openpty, [ :buffer_out, :buffer_out, :buffer_out, :buffer_in, :buffer_in ], :int
attach_function :log... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/samples/qsort_ractor.rb | samples/qsort_ractor.rb | # See the ffi wiki for how to use FFI with Ractors:
# https://github.com/ffi/ffi/wiki/Ractors
require 'ffi'
class Ractor
# compat with Ruby-3.4 and older
alias value take unless method_defined? :value
end
module LibC
extend FFI::Library
ffi_lib FFI::Library::LIBC
callback :qsort_cmp, [ :pointer, :pointer ]... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/samples/inotify.rb | samples/inotify.rb | require 'ffi'
module Inotify
extend FFI::Library
ffi_lib FFI::Library::LIBC
class Event < FFI::Struct
layout \
:wd, :int,
:mask, :uint,
:cookie, :uint,
:len, :uint
end
attach_function :init, :inotify_init, [ ], :int
attach_function :add_watch, :inotify_add_watch, [ :int, :string... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/samples/hello_ractor.rb | samples/hello_ractor.rb | # See the ffi wiki for how to use FFI with Ractors:
# https://github.com/ffi/ffi/wiki/Ractors
require 'ffi'
class Ractor
# compat with Ruby-3.4 and older
alias value take unless method_defined? :value
end
module Foo
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function("cputs", "puts", [ :string ]... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/samples/gettimeofday.rb | samples/gettimeofday.rb | require 'ffi'
require 'rbconfig'
class Timeval < FFI::Struct
layout tv_sec: :ulong, tv_usec: :ulong
end
module LibC
extend FFI::Library
if FFI::Platform.windows?
ffi_lib RbConfig::CONFIG["LIBRUBY_SO"]
else
ffi_lib FFI::Library::LIBC
end
attach_function :gettimeofday, [ :pointer, :pointer ], :int
en... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/ext/ffi_c/extconf.rb | ext/ffi_c/extconf.rb | #!/usr/bin/env ruby
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
require 'mkmf'
require 'rbconfig'
def system_libffi_usable?
# We need pkg_config or ffi.h
libffi_ok = pkg_config("libffi") ||
have_header("ffi.h") ||
find_header("ffi.h", "/usr/local/include", "/usr/include/ffi",
... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/ffi_spec.rb | spec/ffi/ffi_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "FFI" do
describe ".map_library_name" do
let(:prefix) { FFI::Platform::LIBPREFIX }
let(:suffix) { FFI::Platform::LIBSUFFIX }
it "should add platf... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/union_spec.rb | spec/ffi/union_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
module UnionSpec
module LibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
Types = {
's8' => [:char, :c, 1],
's16' => [:short, :s, 0xff0],
's32' => [:... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/buffer_spec.rb | spec/ffi/buffer_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "Buffer#total" do
[1,2,3].each do |i|
{ :char => 1, :uchar => 1, :short => 2, :ushort => 2, :int => 4,
:uint => 4, :long => FFI::Type::LONG.size, :ulo... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/string_spec.rb | spec/ffi/string_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "String tests" do
include FFI
module StrLibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
attach_function :ptr_ret_pointer, [ :pointer, :int], ... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/library_spec.rb | spec/ffi/library_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
module TestEnumValueRactor
extend FFI::Library
enum :something, [:one, :two]
freeze
end
describe "Library" do
describe ".enum_value" do
m = Module.new do
... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/variadic_spec.rb | spec/ffi/variadic_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
module VariadicSpec
describe "Function with variadic arguments" do
module LibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
enum :enum_type1, [:c1, :c2]
... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/type_spec.rb | spec/ffi/type_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe FFI::Type do
it 'has a memsize function', skip: RUBY_ENGINE != "ruby" do
base_size = ObjectSpace.memsize_of(Object.new)
size = ObjectSpace.memsize_of(F... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/enum_spec.rb | spec/ffi/enum_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
module TestEnum0
extend FFI::Library
end
module TestEnum1
extend FFI::Library
ffi_lib TestLibrary::PATH
enum [:c1, :c2, :c3, :c4]
enum [:c5, 42, :c6, :c7, :c8]... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/function_spec.rb | spec/ffi/function_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
module FunctionSpec
describe FFI::Function do
module LibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
attach_function :testFunctionAdd, [:int, :int, :po... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/function_type_spec.rb | spec/ffi/function_type_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "FFI::FunctionType", skip: RUBY_ENGINE != "ruby" do
it 'is initialized with return type and a list of parameter types' do
function_type = FFI::FunctionType.... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/struct_spec.rb | spec/ffi/struct_spec.rb | # -*- encoding: utf-8 -*-
#
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
module StructSpecs
describe "Struct aligns fields correctly" do
it "char, followed by an int" do
class CIStruct < FFI::Struct
layout ... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | true |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/dup_spec.rb | spec/ffi/dup_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "Pointer#dup" do
it "clone should be independent" do
p1 = FFI::MemoryPointer.new(:char, 1024)
p1.put_string(0, "test123");
p2 = p1.dup
p1.put_st... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/async_callback_spec.rb | spec/ffi/async_callback_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
module AsyncCallbackSpec
describe "async callback" do
module LibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
AsyncIntCallback = callback [ :int ], :voi... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/long_double_spec.rb | spec/ffi/long_double_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
require 'bigdecimal'
module LongDoubleSpec
# long double not yet supported on TruffleRuby
describe ":long_double arguments and return values" do
module LibTest
exten... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/bitmask_spec.rb | spec/ffi/bitmask_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
module TestBitmask0
extend FFI::Library
end
module TestBitmask1
extend FFI::Library
ffi_lib TestLibrary::PATH
bitmask [:c1, :c2, :c3, :c4]
bitmask [:c5, 2, :c6... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | true |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/struct_callback_spec.rb | spec/ffi/struct_callback_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe FFI::Struct, ' with inline callback functions' do
it 'should be able to define inline callback field' do
expect(module CallbackMember1
extend FFI::Lib... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/number_spec.rb | spec/ffi/number_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
module NumberSpec
describe "Function with primitive integer arguments" do
module LibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
attach_function :ret_s... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/managed_struct_spec.rb | spec/ffi/managed_struct_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "Managed Struct" do
include FFI
module ManagedStructTestLib
extend FFI::Library
ffi_lib TestLibrary::PATH
attach_function :ptr_from_address, [ FFI... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/typedef_spec.rb | spec/ffi/typedef_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "Custom type definitions" do
it "attach_function with custom typedef" do
module CustomTypedef
extend FFI::Library
ffi_lib TestLibrary::PATH
... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/fork_spec.rb | spec/ffi/fork_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
if Process.respond_to?(:fork)
describe "Callback in conjunction with fork()" do
libtest = Module.new do
extend FFI::Library
ffi_lib TestLibrary::PATH
... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/strptr_spec.rb | spec/ffi/strptr_spec.rb | # -*- encoding: utf-8 -*-
#
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "functions returning :strptr" do
it "can attach function with :strptr return type" do
expect do
Module.new do
exten... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/struct_initialize_spec.rb | spec/ffi/struct_initialize_spec.rb | #
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe FFI::Struct, ' with an initialize function' do
it "should call the initialize function" do
class StructWithInitialize < FFI::Struct
layout :string, :s... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
ffi/ffi | https://github.com/ffi/ffi/blob/88f34306f5be615d61e780f931554dc8109252ca/spec/ffi/gc_compact_spec.rb | spec/ffi/gc_compact_spec.rb | # -*- rspec -*-
# encoding: utf-8
#
# Tests to verify correct implementation of compaction callbacks in rb_data_type_t definitions.
#
# Compaction callbacks update moved VALUEs.
# In ruby-2.7 they are invoked only while GC.compact or GC.verify_compaction_references.
# Ruby constants are usually moved, but local variabl... | ruby | BSD-3-Clause | 88f34306f5be615d61e780f931554dc8109252ca | 2026-01-04T15:58:11.213459Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.