Class: Struct
Overview
Author: Stefano Harding <[email protected]> License: Apache License, Version 2.0 Copyright: © 2014-2015 Stefano Harding
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Direct Known Subclasses
Instance Method Summary collapse
-
#attributes ⇒ Hash
Get a hash with names and values of all instance variables.
-
#object_state(data = nil) ⇒ Object
Get or set state of object.
Instance Method Details
#attributes ⇒ Hash
Get a hash with names and values of all instance variables.
43 44 45 46 47 |
# File 'lib/garcon/core_ext/struct.rb', line 43 def attributes h = {} each_pair { |key, value| h[key] = value } h end |
#object_state(data = nil) ⇒ Object
Get or set state of object. You can think of #object_state as an in-code form of marshalling.
24 25 26 27 28 29 30 31 32 |
# File 'lib/garcon/core_ext/struct.rb', line 24 def object_state(data=nil) if data data.each_pair {|k,v| send(k.to_s + "=", v)} else data = {} each_pair{|k,v| data[k] = v} data end end |