Forum: Ruby how to use it: require

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9c7e3e773ac08cb6e7ae2f4f7eeadaa6?d=identicon&s=25 Servando Garcia (Guest)
on 2006-03-05 16:26
(Received via mailing list)
I have a custom file filled with a word list. How do call it in my main
program.
I have tried "require   wordlist" but ruby can't find the file
In C/C++ I would have used Include<wordlist.h> or for python I would
have used "import wordlist" so long as the wordlist was placed in the
same directory I am good. So how do I do this using ruby



Before I forget I want to thank everyone for their help. I am really
liking Ruby and I finally understand how to use symbols



Sam Garcia
26077118d96b5113414b73edcc2eaf83?d=identicon&s=25 Diego Cano Lagneaux (Guest)
on 2006-03-05 16:38
(Received via mailing list)
> I have a custom file filled with a word list. How do call it in my main
> program.
> I have tried "require   wordlist" but ruby can't find the file
> In C/C++ I would have used Include<wordlist.h> or for python I would
> have used "import wordlist" so long as the wordlist was placed in the
> same directory I am good. So how do I do this using ruby
>
Call the file wordlist.rb, then require it like this:

require "wordlist"

elKano
Bc6d88907ce09158581fbb9b469a35a3?d=identicon&s=25 James Britt (Guest)
on 2006-03-05 16:38
(Received via mailing list)
Servando Garcia wrote:
> I have a custom file filled with a word list. How do call it in my main
> program.
> I have tried "require   wordlist" but ruby can't find the file
> In C/C++ I would have used Include<wordlist.h> or for python I would
> have used "import wordlist" so long as the wordlist was placed in the
> same directory I am good. So how do I do this using ruby
>

require is a method call that takes a string.


require 'wordlist'

'wordlist' needs to be in some directory that is part of the Ruby
interpreter's current load path.

http://www.ruby-doc.org/core/classes/Kernel.html#M001980


>
>
> Before I forget I want to thank everyone for their help. I am really
> liking Ruby and I finally understand how to use symbols


Great! Now learn to abuse them!




--
James Britt

http://www.ruby-doc.org       - Ruby Help & Documentation
http://www.artima.com/rubycs/ - The Journal By & For Rubyists
http://www.rubystuff.com      - The Ruby Store for Ruby Stuff
http://www.30secondrule.com   - Building Better Tools
This topic is locked and can not be replied to.