lib/glib2.rb in glib2-3.3.7 vs lib/glib2.rb in glib2-3.3.8

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (C) 2005-2018 Ruby-GNOME2 Project Team +# Copyright (C) 2005-2019 Ruby-GNOME Project Team # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. @@ -146,26 +146,53 @@ end end class Enum + class << self + def try_convert(value) + if value.is_a?(self) + value + else + find(value) + end + end + + def _load(obj) + new(Marshal.load(obj)) + end + end + def _dump(limit) Marshal.dump(to_i, limit) end - - def self._load(obj) - new(Marshal.load(obj)) - end end class Flags - def _dump(limit) - Marshal.dump(to_i, limit) + class << self + def try_convert(value) + case value + when self + value + when Integer, String, Symbol, Array + begin + new(value) + rescue ArgumentError + nil + end + else + nil + end + end + + def _load(obj) + new(Marshal.load(obj)) + end end - def self._load(obj) - new(Marshal.load(obj)) + def _dump(limit) + Marshal.dump(to_i, limit) end # FIXME def inspect values = self.class.values