Creating a setter method that takes extra arguments in Ruby
问题 I'm trying to write a method that acts as a setter and takes some extra arguments besides the assigned value. Silly example: class WordGenerator def []=(letter, position, allowed) puts "#{letter}#{allowed ? ' now' : ' no longer'} allowed at #{position}" end def allow=(letter, position, allowed) # ... end end Writing it as an indexer works and I can call it like this: gen = WordGenerator.new gen['a', 1] = true # or explicitly: gen.[]=('a', 1, true) But when I try any of the following, the