File: safe_assignment.rb

package info (click to toggle)
ruby-hashie 5.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: ruby: 7,049; sh: 8; makefile: 6
file content (18 lines) | stat: -rw-r--r-- 400 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Hashie
  module Extensions
    module Mash
      module SafeAssignment
        def custom_writer(key, *args) #:nodoc:
          if !key?(key) && respond_to?(key, true)
            raise ArgumentError, "The property #{key} clashes with an existing method."
          end
          super
        end

        def []=(*args)
          custom_writer(*args)
        end
      end
    end
  end
end