Refactored Style to remove usage of method_missing

This commit is contained in:
2026-01-09 08:20:27 -06:00
parent 0fac4a0397
commit a30d66fafb

View File

@@ -19,6 +19,30 @@ module CyberarmEngine
class Style
attr_reader :hash
%i[
x y z width height min_width min_height max_width max_height color background
background_image background_image_mode background_image_color
background_nine_slice background_nine_slice_mode background_nine_slice_color background_nine_slice_from_edge
background_nine_slice_left background_nine_slice_top background_nine_slice_right background_nine_slice_bottom
border_color border_color_left border_color_right border_color_top border_color_bottom
border_thickness border_thickness_left border_thickness_right border_thickness_top border_thickness_bottom
padding padding_left padding_right padding_top padding_bottom
margin margin_left margin_right margin_top margin_bottom
background_canvas background_nine_slice_canvas background_image_canvas border_canvas
fraction_background scroll fill text_wrap v_align h_align delay tag
image_width image_height
default hover active disabled
].each do |item|
define_method(item) do
@hash[item]
end
define_method(:"#{item}=") do |value|
@hash[item] = value
end
end
def initialize(hash = {})
h = hash
# h = Marshal.load(Marshal.dump(hash))
@@ -33,18 +57,5 @@ module CyberarmEngine
@hash = h
end
def method_missing(method, *args)
if method.to_s.end_with?("=")
raise "Did not expect more than 1 argument" if args.size > 1
@hash[method.to_s.sub("=", "").to_sym] = args.first
elsif args.empty?
@hash[method]
else
raise ArgumentError, "Did not expect arguments"
end
end
end
end