Class: MiniRuby::NativeFunction
- Inherits:
-
Object
- Object
- MiniRuby::NativeFunction
- Extended by:
- T::Sig
- Defined in:
- lib/miniruby/native_function.rb
Overview
A native function that is available in MiniRuby
Constant Summary collapse
- Func =
T.type_alias { T.proc.params(vm: VM, args: T::Array[Object]).returns(Object) }
Instance Attribute Summary collapse
-
#func ⇒ Object
readonly
: Func.
-
#name ⇒ Object
readonly
: Symbol.
-
#param_count ⇒ Object
readonly
: Integer.
Instance Method Summary collapse
-
#call(vm, args) ⇒ Object
: (VM vm, Array args) -> Object.
-
#initialize(name:, param_count: 0, &func) ⇒ NativeFunction
constructor
: (name: Symbol, ?param_count: Integer) { (?) -> untyped } -> void.
Constructor Details
#initialize(name:, param_count: 0, &func) ⇒ NativeFunction
: (name: Symbol, ?param_count: Integer) { (?) -> untyped } -> void
23 24 25 26 27 |
# File 'lib/miniruby/native_function.rb', line 23 def initialize(name:, param_count: 0, &func) @name = name @func = func @param_count = param_count end |
Instance Attribute Details
#func ⇒ Object (readonly)
: Func
20 21 22 |
# File 'lib/miniruby/native_function.rb', line 20 def func @func end |
#name ⇒ Object (readonly)
: Symbol
12 13 14 |
# File 'lib/miniruby/native_function.rb', line 12 def name @name end |
#param_count ⇒ Object (readonly)
: Integer
15 16 17 |
# File 'lib/miniruby/native_function.rb', line 15 def param_count @param_count end |
Instance Method Details
#call(vm, args) ⇒ Object
: (VM vm, Array args) -> Object
30 31 32 33 34 35 36 37 |
# File 'lib/miniruby/native_function.rb', line 30 def call(vm, args) arg_count = args.length - 1 if arg_count != @param_count raise ArgumentError, "#{@name}: got #{arg_count} arguments, expected #{@param_count}" end @func.call(vm, args) end |