2017年7月17日月曜日

[Ruby] first monkey patch(Mechanize::Form::SelectList )

This is my first monkey patch(for Mechanize::Form::SelectList)

This monkey patch is even if the SelectList is not multiple, we can clear selectitems by select_none(original code was set first.value when select_none).

class Mechanize::Form::SelectList < Mechanize::Form::MultiSelectList
  def value
    value = super
    if value.length > 0
      value.last
    elsif @options.length > 0
      # @options.first.value
      nil
    else
      nil
    end
  end
end