Sha256: 2dc347d88198b8b7b3e3753b582386d7791bffb73459a1cff355f2ea4539d36f
Contents?: true
Size: 1.21 KB
Versions: 1
Compression:
Stored size: 1.21 KB
Contents
# # 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. # module Reality #nodoc # Base class used for elements configurable via options class BaseElement def initialize(options = {}) self.options = options yield self if block_given? end def options=(options) options.each_pair do |k, v| keys = k.to_s.split('.') target = self keys[0, keys.length - 1].each do |target_accessor_key| target = target.send target_accessor_key.to_sym end begin target.send "#{keys.last}=", v rescue NoMethodError raise "Attempted to configure property \"#{keys.last}\" on #{self.class} but property does not exist." end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
reality-core-1.2.0 | lib/reality/base_element.rb |