ruboto and sub-directories

17 views
Skip to first unread message

Nick Keighley

unread,
Jan 1, 2016, 6:19:34 PM1/1/16
to Ruboto (JRuby on Android)
Is it possible to put my source in a subdirectory of jruby/  ?  And have the requirecalls work ?

Of course I can put my files there but SCRIPTS in Ruboto IRB doesn't allow me to access
them (in any obvious way)

Even if I change the current directory in IRB (eg. "Dir.chdir 'subdir'") then "load 'myfile.rb'" it
doesn't work. It says it can't find the file. OTH "load 'subdir/myfile.rb'" *does* work. But then
requires in myfile.rb don't work. Again the file can't be found.

If I run irb on a PC I can make this work because I start irb like this "irb -I."
So is there a way to tell irb what path it should be using and where to start looking for its
require files?

Suller Andras

unread,
Jan 1, 2016, 8:56:54 PM1/1/16
to rub...@googlegroups.com
I haven't used Ruboto recently, but in normal Ruby, you'd need to add
"subdir" to $LOAD_PATH, like this:

$LOAD_PATH.unshift('subdir')

Then `load 'myfile.rb' ` should work.
I believe there is a way to set your work directory in Ruboto IRB, but
I cannot recall how.

Is there any reason why you are using "load" instead of "require"? I
never seen anyone using "load" before.

Happy New Year!
Andras
> --
> You received this message because you are subscribed to the Google Groups
> "Ruboto (JRuby on Android)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ruboto+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nick Keighley

unread,
Jan 2, 2016, 8:53:21 AM1/2/16
to Ruboto (JRuby on Android)
On Fri, Jan 1, 2016 at 2:21 AM, Nick Keighley
<nick_keigh...@hotmail.com> wrote:
On Saturday, 2 January 2016 01:56:54 UTC, Andras Suller wrote:

this is specifically about ruboto running on an Android tablet


>> Is it possible to put my source in a subdirectory of jruby/  ?  And have the
>> require calls work ?

>>
>> Of course I can put my files there but SCRIPTS in Ruboto IRB doesn't allow
>> me to access them (in any obvious way)
>>
>> Even if I change the current directory in IRB (eg. "Dir.chdir 'subdir'")
>> then "load 'myfile.rb'" it
>> doesn't work. It says it can't find the file. OTH "load 'subdir/myfile.rb'"
>> *does* work. But then requires in myfile.rb don't work. Again the file
>> can't be found.

this can be fixed by using
  require_relative './myfile2'
 
But then I can't use the built in editor to edit scripts as it too only looks
at ../jruby but not its subdirectories


>> If I run irb on a PC I can make this work because I start irb like this "irb
>> -I."
>> So is there a way to tell irb what path it should be using and where to
>> start looking for its
>> require files?
>
>    I haven't used Ruboto recently, but in normal Ruby, you'd need to add
>    "subdir" to $LOAD_PATH, like this:
>
>    $LOAD_PATH.unshift('subdir')

yuk. "require_relative" seems slightly cleaner


>    Then `load 'myfile.rb' ` should work.
>    I believe there is a way to set your work directory in Ruboto IRB, but
>    I cannot recall how.

:-)


>    Is there any reason why you are using "load" instead of "require"? I
>    never seen anyone using "load" before.

I'm brand new to Ruby (started learning it over the holiday) so I may indeed
be doing very odd things. I am reading "Eloquent Ruby" so hopefully this
will teach me idiomatic Ruby.

I'm using "load" because, I understand, it loads unconditionally so If I
change the source it will actually get reloaded. I understand "require"
only loads stuff the first time.

>    Happy New Year!
>    Andras

Happy New Yesr too!

Suller Andras

unread,
Jan 8, 2016, 10:37:35 PM1/8/16
to rub...@googlegroups.com
On Sat, Jan 2, 2016 at 9:53 PM, Nick Keighley
<nick_keigh...@hotmail.com> wrote:
> On Fri, Jan 1, 2016 at 2:21 AM, Nick Keighley
> <nick_keigh...@hotmail.com> wrote:
> On Saturday, 2 January 2016 01:56:54 UTC, Andras Suller wrote:
>
> this is specifically about ruboto running on an Android tablet
>
>>> Is it possible to put my source in a subdirectory of jruby/ ? And have
>>> the
>>> require calls work ?
>>>
>>> Of course I can put my files there but SCRIPTS in Ruboto IRB doesn't
>>> allow
>>> me to access them (in any obvious way)
>>>
>>> Even if I change the current directory in IRB (eg. "Dir.chdir 'subdir'")
>>> then "load 'myfile.rb'" it
>>> doesn't work. It says it can't find the file. OTH "load
>>> 'subdir/myfile.rb'"
>>> *does* work. But then requires in myfile.rb don't work. Again the file
>>> can't be found.
>
> this can be fixed by using
> require_relative './myfile2'
>
> But then I can't use the built in editor to edit scripts as it too only
> looks
> at ../jruby but not its subdirectories

When I used my tablet for ruby, I used VimTouch instead of the
built-in editor and executed the ruby scripts in a terminal emulator.
If you are new to programming, then you probably find Vim very hard to
use so this may not be suitable for you.

>
>> Then `load 'myfile.rb' ` should work.
>> I believe there is a way to set your work directory in Ruboto IRB, but
>> I cannot recall how.
>
> :-)
>
>> Is there any reason why you are using "load" instead of "require"? I
>> never seen anyone using "load" before.
>
> I'm brand new to Ruby (started learning it over the holiday) so I may indeed
> be doing very odd things. I am reading "Eloquent Ruby" so hopefully this
> will teach me idiomatic Ruby.
>
> I'm using "load" because, I understand, it loads unconditionally so If I
> change the source it will actually get reloaded. I understand "require"
> only loads stuff the first time.

It seems like "load" does not care about the $LOAD_PATH, you need to
use full path names.
Executing from a terminal reloads your ruby files, so you can use
"require". The downside is that you need to switch between the
terminal and the editor every time you want to execute your script (it
is easy with an external keyboard).

So as a workaround, I'd put everything in one ruby file. It would
solve the problem with the require/load and you could use the built-in
editor in Ruboto. Or use a laptop instead of a tablet :)

Cheers,
Andras
Reply all
Reply to author
Forward
0 new messages