A one-liner solution for ActiveRecord::Base#to_param

 @args
   String A non empty format string
   Symbol An existing attribute name
 @example
   to_param :name
   to_param ":id-:awesome-name"
   to_param "static"
354301
def to_param(args)
        case args
        when String
          define_method "to_param" do
            args.gsub(/:(\w+)/) {|method| send(method[1..-1]).to_s.parameterize }
          end

          if args.empty?
            raise ArgumentError.new("args can not be an empty string")
          end
        when Symbol
          define_method "to_param" do
            "#{id}-#{send(args).parameterize}"
          end
        else
          raise ArgumentError.new("args can only be string or symbol")
        end
    end
1234851
def parameter_to_field(self, name):
        
        if name not in self._parameters:
            raise ValueError("no '%s' parameter found" % (name))
        if self._fields.count(name) > 0:
            raise ValueError("field with name '%s' already exists" % (name))

        data = np.array([self._parameters[name]]*self._num_fix)

        self.rm_parameter(name)
        self.add_field(name, data)
637348
def _normalize_args(action = nil, options = {})
        options = super(action, options)
        case action
        when NilClass
        when Hash
          options = action
        when String, Symbol
          action = action.to_s
          key = action.include?(?/) ? :template : :action
          options[key] = action
        else
          if action.respond_to?(:permitted?) && action.permitted?
            options = action
          else
            options[:partial] = action
          end
        end

        options
      end
537019
def method_missing(method_id, *arguments, &block)#:nodoc:

      # If the missing method is  XXX_without_static_rc, define XXX
      # using the superclass ActiveRecord::Base method_missing then
      # Finally, alias chain it to XXX_with_static_rc
      if ((match = method_id.to_s.match(/(.*)_without_static_rc$/)) &&
          (base_method_id = match[1]))
        begin
          return super(base_method_id, *arguments, &block)
        ensure
          define_static_rc_alias(base_method_id)
        end
      end

      # If the missing method is a finder like find_by_name
      # Define on the class then invoke find_by_name_with_static_rc
      if match = ActiveRecord::DynamicFinderMatch.match(method_id)
        attribute_names = match.attribute_names
        if all_attributes_exists?(attribute_names) &&  match.finder?
          attributes = construct_attributes_from_arguments(attribute_names, arguments)
          method_name = define_static_record_finder_method(method_id, match.finder, match.bang?, attributes)
          return self.send method_name, *arguments
        end
      end

      #If nothing matches, invoke the super
      super(method_id, *arguments, &block)
    end
219761
def method_missing(mthd, *args, &block)
      new_recs = args.reduce([]) {|a, i| a.push(formatted_name(i)) if i.class.ancestors.include?(ActiveRecord::Base); a}
      result = @set.send(mthd,
        *(args.map do |arg|
            arg.class.ancestors.include?(ActiveRecord::Base) ? formatted_name(arg) : arg
          end
        ),
        &block
      )
      @set.to_a.select {|i| new_recs.include? i }.each {|f| @flagged << f}
      result
    end
237926
def [](attr)
      return nil unless instance_variable_defined?(:@attributes) and @attributes.is_a?(Hash)
      @attributes[attr] or (attr.is_a?(String) ? @attributes[attr.to_sym] : @attributes[attr.to_s])
    end
986056
def attributes=(attributes)
      model = self.model
      attributes.each do |name, value|
        case name
          when String, Symbol
            if model.allowed_writer_methods.include?(setter = "#{name}=")
              __send__(setter, value)
            else
              raise ArgumentError, "The attribute '#{name}' is not accessible in #{model}"
            end
          when Associations::Relationship, Property
            # only call a public #typecast (e.g. on Property instances)
            if name.respond_to?(:typecast)
              value = name.typecast(value)
            end
            self.persistence_state = persistence_state.set(name, value)
        end
      end
    end
838129
def to_h
      attributes.transform_values { |val| val.is_a?(Symbol) ? val.to_s : val }
    end
934320
def method_missing(name, *args, &block)
      return attr(name[0..-2], args[0]) if args.size == 1 and name[-1] == '='
    end
658048
def to_format(self, attr):
        
        try:
            _attr = self._to[attr]
        except KeyError:
            try:
                _attr = self._to[attr.lower()]
            except:
                _attr = ''

        if _attr:
            return factory(saml.Attribute,
                           name=_attr,
                           name_format=self.name_format,
                           friendly_name=attr)
        else:
            return factory(saml.Attribute, name=attr)
559225
def parse_attribute
      ns_id, name_id, val_str_id, flags, val = @io.read(4*5).unpack("V*")
      key = @strings[name_id]
      unless ns_id == 0xFFFFFFFF
        ns = @strings[ns_id] 
        prefix = ns.sub(/.*\//,'')
        unless @ns.include? ns
          @ns << ns
          @doc.root.add_namespace(prefix, ns)
        end
        key = "#{prefix}:#{key}"
      end
      value = convert_value(val_str_id, flags, val)
      return key, value
    end
1356793
def expand_attribute_names_for_aggregates(attribute_names)
      attribute_names.map { |attribute_name|
        unless (aggregation = reflect_on_aggregation(attribute_name.to_sym)).nil?
          aggregate_mapping(aggregation).map do |field_attr, _|
            field_attr.to_sym
          end
        else
          attribute_name.to_sym
        end
      }.flatten
    end
631217
def method_missing(attr_name)
      member_sym = attr_name.id2name.to_sym
      self[member_sym]
    rescue ArgumentError # `member_sym` field doesn't exist.
      raise(NoMethodError.new("undefined method '#{attr_name}' for #{self}"))
    end
997804
def process_attributes(attributes = nil)
      return attributes if attributes.blank?
      multi_parameter_attributes = {}
      new_attributes = {}
      attributes.each_pair do |key, value|
        if key.match(DATE_KEY_REGEX)
          match = key.to_s.match(DATE_KEY_REGEX)
          found_key = match[1]
          index = match[2].to_i
          (multi_parameter_attributes[found_key] ||= {})[index] = value.empty? ? nil : value.send("to_#{$3}")
        else
          new_attributes[key] = value
        end
      end

      multi_parameter_attributes.empty? ? new_attributes : process_multiparameter_attributes(multi_parameter_attributes, new_attributes)
    end
756159
def format_param(p):
    ""
    arg_prefix = arg_prefixes.get(p.kind, '') # asterisk prefix for *args and **kwargs
    res = f"**{arg_prefix}{code_esc(p.name)}**"
    if hasattr(p, 'annotation') and p.annotation != p.empty: res += f':{anno_repr(p.annotation)}'
    if p.default != p.empty:
        default = getattr(p.default, 'func', p.default)
        default = getattr(default, '__name__', default)
        res += f'=***`{repr(default)}`***'
    return res
751672
def attribute_name=(attribute_name)
      if attribute_name.nil?
        fail ArgumentError, "attribute_name cannot be nil"
      end

      if attribute_name.to_s.length < 1
        fail ArgumentError, "invalid value for 'attribute_name', the character length must be great than or equal to 1."
      end

      @attribute_name = attribute_name
    end
631592
def to_s(attributes=nil)
      content = printable_content(attributes)
      content_s = content.pp_s(:single_line) unless content.empty?
      "#{print_class_and_id}#{content_s}"
    end