lib/ury_rapid/services/responses/structure_builder.rb
# Defines a common structure that can be reused for multiple commands
#
# Given a name and arguments, this creates a method of that name that,
# when called with a response code, expands to a #struct call with that
# code and the provided arguments.
#
# For convenience, multiple codes may be provided to the shortcut, with
# the same result as that from invoking the shortcut once for each code.
#
# When the same structure is repeated multiple times with only the
# response code varying, one can instead #def_struct the structure once
# and then call the created method with those codes, saving time and
# RSI.
#
# @api      public
# @example  Defining a common structure with no argument.
#   def_struct :unary
#   # We can now write 'unary PLAY' instead of 'struct PLAY'.
# @example  Defining a common structure with arguments.
#   # Here, 'option_id' is an argument shortcut, and 'config_setting'
#   # is a type.
#   def_struct :config, option_id, config_setting(:setting)
#   # We can now write 'config CONFIG_SETTING, CONFIG_SETTING_INDEXED'
#   # instead of the rather long-winded
#   # 'struct CONFIG_SETTING, option_id, config_setting(:setting)' and
#   # 'struct CONFIG_SETTING_INDEXED, option_id,
#   #  config_setting(:setting)'.
#
# @return [null]
Defines a common structure that can be reused for multiple commands
Given a name and arguments, this creates a method of that name that,
when called with a response code, expands to a #struct call with that
code and the provided arguments.

For convenience, multiple codes may be provided to the shortcut, with
the same result as that from invoking the shortcut once for each code.

When the same structure is repeated multiple times with only the
response code varying, one can instead #def_struct the structure once
and then call the created method with those codes, saving time and
RSI.
Defines a common structure that can be reused for multiple commands Given a name and arguments this creates a method of that name that when called with a response code expands to a #struct call with that code and the provided arguments . For convenience multiple codes may be provided to the shortcut with the same result as that from invoking the shortcut once for each code . When the same structure is repeated multiple times with only the response code varying one can instead #def_struct the structure once and then call the created method with those codes saving time and RSI .
def def_struct(name, *arguments)
          create_method(name) do |*symbols|
            symbols.each { |symbol| struct(symbol, *arguments) }
          end
        end
def def_struct ( name , * arguments ) create_method ( name ) do | * symbols | symbols . each { | symbol | struct ( symbol , * arguments ) } end end
Defines a common structure that can be reused for multiple commands
Given a name and arguments, this creates a method of that name that,
when called with a response code, expands to a #struct call with that
code and the provided arguments.
Defines a common structure that can be reused for multiple commands Given a name and arguments this creates a method of that name that when called with a response code expands to a #struct call with that code and the provided arguments .
None
null
name
arguments
api
None
example
Defining a common structure with no argument. def_struct :unary # We can now write 'unary PLAY' instead of 'struct PLAY'.
Defining a common structure with no argument . def_struct : unary # We can now write ' unary PLAY ' instead of ' struct PLAY ' .
example
Defining a common structure with arguments. # Here, 'option_id' is an argument shortcut, and 'config_setting' # is a type. def_struct :config, option_id, config_setting(:setting) # We can now write 'config CONFIG_SETTING, CONFIG_SETTING_INDEXED' # instead of the rather long-winded # 'struct CONFIG_SETTING, option_id, config_setting(:setting)' and # 'struct CONFIG_SETTING_INDEXED, option_id, # config_setting(:setting)'.
Defining a common structure with arguments . # Here ' option_id ' is an argument shortcut and ' config_setting ' # is a type . def_struct : config option_id config_setting ( : setting ) # We can now write ' config CONFIG_SETTING CONFIG_SETTING_INDEXED ' # instead of the rather long - winded # ' struct CONFIG_SETTING option_id config_setting ( : setting ) ' and # ' struct CONFIG_SETTING_INDEXED option_id # config_setting ( : setting ) ' .