Sha256: 759867c62a0fff8e50edbcc74dab5fee44b47316c556108d506d5996a8fc0fe0

Contents?: true

Size: 810 Bytes

Versions: 18

Compression:

Stored size: 810 Bytes

Contents

# DynamicAccessors provides support for
# simply setting and getting values of any kind from
# any object that includes it.
#
#   require 'dynamic_accessors'
#
#   class Foo
#     include DynamicAccessors
#   end
#
#   foo = Foo.new
#   foo.bar = "Hello World"
#   foo.friends = ['a', 'b', 'c']
#   puts "foo.bar: #{foo.bar}"
#   puts "foo.friends: #{foo.friends.join(', ')}"

module DynamicAccessors
  
  def initialize(*params)
    super
    @missing_params_hash = Hash.new
  end

  def method_missing(method, *params, &block)
    if(method.to_s.match(/=$/))
      method = method.to_s.gsub('=', '').to_sym
      return @missing_params_hash[method] = params.shift
    else
      return @missing_params_hash[method] if @missing_params_hash.keys.collect(&:to_sym).include?(method)
    end
    super
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
sprout-0.7.220 lib/sprout/dynamic_accessors.rb
sprout-0.7.220-x86-linux lib/sprout/dynamic_accessors.rb
sprout-0.7.220-x86-darwin-10 lib/sprout/dynamic_accessors.rb
sprout-0.7.220-mswin32 lib/sprout/dynamic_accessors.rb
sprout-0.7.220-darwin lib/sprout/dynamic_accessors.rb
sprout-0.7.219 lib/sprout/dynamic_accessors.rb
sprout-0.7.219-x86-linux lib/sprout/dynamic_accessors.rb
sprout-0.7.219-i686-darwin10 lib/sprout/dynamic_accessors.rb
sprout-0.7.219-mswin32 lib/sprout/dynamic_accessors.rb
sprout-0.7.219-darwin lib/sprout/dynamic_accessors.rb
sprout-0.7.218 lib/sprout/dynamic_accessors.rb
sprout-0.7.218-x86-linux lib/sprout/dynamic_accessors.rb
sprout-0.7.218-mswin32 lib/sprout/dynamic_accessors.rb
sprout-0.7.218-darwin lib/sprout/dynamic_accessors.rb
sprout-0.7.217-x86-linux lib/sprout/dynamic_accessors.rb
sprout-0.7.217-mswin32 lib/sprout/dynamic_accessors.rb
sprout-0.7.217-darwin lib/sprout/dynamic_accessors.rb
sprout-0.7.217 lib/sprout/dynamic_accessors.rb