Class: Selenium::WebDriver::BiDi::Struct

Inherits:
Struct
  • Object
show all
Defined in:
rb/lib/selenium/webdriver/bidi/struct.rb

Class Method Summary collapse

Class Method Details

.camel_to_snake(camel_str) ⇒ Object



35
36
37
# File 'rb/lib/selenium/webdriver/bidi/struct.rb', line 35

def camel_to_snake(camel_str)
  camel_str.gsub(/([A-Z])/, '_\1').downcase
end

.new(*args, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'rb/lib/selenium/webdriver/bidi/struct.rb', line 25

def new(*args, &block)
  super(*args) do
    define_method(:initialize) do |**kwargs|
      converted_kwargs = kwargs.transform_keys { |key| self.class.camel_to_snake(key.to_s).to_sym }
      super(*converted_kwargs.values_at(*self.class.members))
    end
    class_eval(&block) if block
  end
end