Skip to content

Commit

Permalink
Update flags.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Jul 20, 2024
1 parent 8b955e1 commit a281098
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/literal/flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ def define(**flags)
@max = unique_values.max
@flags = flags.dup.freeze

flags.each do |name, index|
flags.each do |name, bit|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
# frozen_string_literal: true
def #{name}=(value)
raise Literal::TypeError unless true == value || false == value
@value |= value ? 2 ** #{index} : 0
@value |= value ? 2 ** #{bit} : 0
end
def #{name}?
@value & (2 ** #{index}) > 0
@value & (2 ** #{bit}) > 0
end
RUBY
end
Expand Down Expand Up @@ -66,8 +66,8 @@ def inspect
end

def to_h
self.class.flags.transform_values do |index|
@value & (2 ** index) > 0
self.class.flags.transform_values do |bit|
@value & (2 ** bit) > 0
end
end

Expand Down

0 comments on commit a281098

Please sign in to comment.