Hi,
I have 2 source files...A.rb and B.rb
Methods in A access methods in B and vice versa.
So i put require 'B' in A.rb and require 'A' in B.rb but it gives
NameError.
Please help.
Ver. 1.8
···
--
Posted via http://www.ruby-forum.com/.
Hi,
I have 2 source files...A.rb and B.rb
Methods in A access methods in B and vice versa.
So i put require 'B' in A.rb and require 'A' in B.rb but it gives
NameError.
Please help.
Ver. 1.8
--
Posted via http://www.ruby-forum.com/.
Also provide the us the content of `A.rb` and `B.rb`. we need to look
into the same.
--
Posted via http://www.ruby-forum.com/.
I use ver. 1.8. In that 'require' can access all files in the current
dir.
--
Posted via http://www.ruby-forum.com/.
Hi Marcus,
My main.rb file has some variables that are initialized once and then
they are accessed inside a method.
How should i scope such vars?
--
Posted via http://www.ruby-forum.com/.
Processor.rb
-------
require 'Parser'
Parser.parse("Exhibitors.csv", ",")
def self.processRecord(tile_name, category_name, block_name_arr)
........
end
Parser.rb
---------
require 'Processor'
class Parser
def self.parse(dataFile, delimiter)
..........
processRecord(tile, category, [block1, block2, block3, block4])
..........
end
When i run Processor, it gives a NameError on
Parser.parse("Exhibitors.csv", ",")
Please help.
--
Posted via http://www.ruby-forum.com/.
Rajarshi Chakravarty wrote in post #1137007:
When i run Processor, it gives a NameError on
Parser.parse("Exhibitors.csv", ",")Please help.
Nice! Can you show us the Filesystem structure of those 2 files? Are
they in the same directory ?
--
Posted via http://www.ruby-forum.com/\.
Yes, they are in the same directory.
I think the problem is Processor.rb has some statements that get
executed when it is 'required' in the other file.
I want just the method to be accessible.
How to do that?
--
Posted via http://www.ruby-forum.com/.
Rajarshi Chakravarty wrote in post #1137010:
Yes, they are in the same directory.
I think the problem is Processor.rb has some statements that get
executed when it is 'required' in the other file.
I want just the method to be accessible in the other file.
How to do that?
You need to use `require_relative`, instead of `require`. Please try
this.
--
Posted via http://www.ruby-forum.com/\.
Thank you for your help, Arup.
I was able to solve my problem using $ vars and if __FILE__ == $0 in the
Processor class.
--
Posted via http://www.ruby-forum.com/.
@Arup
You are completely on the wrong track: in Ruby 1.8 there is
no require_relative! Using require is correct.
Am 18.02.2014 10:48, schrieb Arup Rakshit:
Rajarshi Chakravarty wrote in post #1137010:
Yes, they are in the same directory.
I think the problem is Processor.rb has some statements that get
executed when it is 'required' in the other file.
I want just the method to be accessible in the other file.
How to do that?You need to use `require_relative`, instead of `require`. Please try
this.
--
GitHub: stomar (Marcus Stollsteimer) · GitHub
PGP: 0x6B3A101A
Rajarshi Chakravarty wrote in post #1137036:
Thank you for your help, Arup.
I was able to solve my problem using $ vars and if __FILE__ == $0 in the
Processor class.
Nice to hear! But did you try `require_relative` ?
--
Posted via http://www.ruby-forum.com/\.
That sounds so wrong. Global variables usually are considere harmful
or at least really bad style.
You really should try to restructure your code and avoid
circular dependencies if at all possible.
Regards,
Marcus
Am 18.02.2014 13:11, schrieb Rajarshi Chakravarty:
Thank you for your help, Arup.
I was able to solve my problem using $ vars and if __FILE__ == $0 in the
Processor class.
--
GitHub: https://github.com/stomar/
PGP: 0x6B3A101A
unknown wrote in post #1137103:
Am 18.02.2014 10:48, schrieb Arup Rakshit:
You are completely on the wrong track: in Ruby 1.8 there is
no require_relative! Using require is correct.
But as far as I know, to work `require 'Processor'`, the CWD should be
added to the $LOAD_PATH. Am I right ?
--
Posted via http://www.ruby-forum.com/\.