From: Robert Klemme Date: 2010-09-30T01:35:29+09:00 Subject: Re: error message, undefined method in Set On 28.09.2010 22:13, Brian Candler wrote: > Iain Barnett wrote: >>> Then at the top of choice.rb I'd put require 'set'. >> >> That's what I was originally doing, but a lot of the advice I've read on >> structuring projects is to remove the requires from individual >> classes/files and put them in a central file with the name of the app >> under lib. > > Personally I don't support that advice, but it's very much a matter of > personal preference. I like each source file to declare its > dependencies, because it lets them be re-used more easily, although it > is easy to miss some. +1 > I don't know why in your case you have to require set.rb before > choice.rb. If you could boil choice.rb down to a small test case which > demonstrates the problem, it should be fairly easy to identify. But > without seeing the code, I'm only guessing. Basically order should not matter. It seems choice.rb or some file required from there does something bad to Set like you showed in your example. Although, if I think about it: that should be visible: $ ruby19 -e 'class Set;end; class Set < Hash; end' -e:1:in `
': superclass mismatch for class Set (TypeError) Set could be reassigned but even then that would be visible $ ruby19 -e 'class Set;end; Set = Class.new Hash' -e:1: warning: already initialized constant Set Ian, if you really want to know what goes on you could try this at the top of the script, before any requires: set_trace_func lambda {|*a| p a} This will create copious output though. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/