Class: Furud::Functions::Registry
- Inherits:
-
Object
- Object
- Furud::Functions::Registry
- Includes:
- Enumerable, Enumerable[Entry]
- Defined in:
- lib/furud/functions.rb,
sig/furud.rbs
Instance Method Summary collapse
- #[](name) ⇒ Entry?
- #call(name, *args) ⇒ Object
- #each {|arg0| ... } ⇒ self
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #initialize_copy(other) ⇒ Object
- #names ⇒ Array[String]
- #register(name, arity:, volatile: false) {|arg0| ... } ⇒ self
- #size ⇒ Integer
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
57 58 59 |
# File 'lib/furud/functions.rb', line 57 def initialize @entries = {} end |
Instance Method Details
#[](name) ⇒ Entry?
78 |
# File 'lib/furud/functions.rb', line 78 def [](name) = @entries[name.to_s.upcase] |
#call(name, *args) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/furud/functions.rb', line 83 def call(name, *args) entry = self[name] return ErrorValue.new(code: :name) unless entry entry.call(*args) end |
#each {|arg0| ... } ⇒ self
80 |
# File 'lib/furud/functions.rb', line 80 def each(&block) = @entries.values.each(&block) |
#initialize_copy(other) ⇒ Object
61 62 63 64 |
# File 'lib/furud/functions.rb', line 61 def initialize_copy(other) super @entries = other.instance_variable_get(:@entries).dup end |
#names ⇒ Array[String]
79 |
# File 'lib/furud/functions.rb', line 79 def names = @entries.keys.sort.freeze |
#register(name, arity:, volatile: false) {|arg0| ... } ⇒ self
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/furud/functions.rb', line 66 def register(name, arity:, volatile: false, &implementation) raise ArgumentError, "implementation block is required" unless implementation name = name.to_s.upcase raise ArgumentError, "invalid function name: #{name}" unless name.match?(/\A[A-Z][A-Z0-9_.]*\z/) raise ArgumentError, "function already registered: #{name}" if @entries.key?(name) @entries[name] = Entry.new(name: name, arity: arity, volatile: !!volatile, implementation: implementation) self end |
#size ⇒ Integer
81 |
# File 'lib/furud/functions.rb', line 81 def size = @entries.size |