Skip to content

Commit

Permalink
Merge pull request ruby#365 from ydah/use-def_delegators
Browse files Browse the repository at this point in the history
Use `def_delegators` in Lrama::States::Item
  • Loading branch information
yui-knk authored Jan 29, 2024
2 parents 73a6aa9 + 085cd4e commit 56b36fb
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/lrama/states/item.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# TODO: Validate position is not over rule rhs

require "forwardable"

module Lrama
class States
class Item < Struct.new(:rule, :position, keyword_init: true)
extend Forwardable

def_delegators "rule", :lhs, :rhs

# Optimization for States#setup_state
def hash
[rule_id, position].hash
Expand All @@ -20,14 +26,6 @@ def number_of_rest_symbols
rhs.count - position
end

def lhs
rule.lhs
end

def rhs
rule.rhs
end

def next_sym
rhs[position]
end
Expand Down

0 comments on commit 56b36fb

Please sign in to comment.