simple ruby project layout question

Discussion in 'Ruby' started by Tom Cloyd, Feb 14, 2009.

  1. Tom Cloyd

    Tom Cloyd Guest

    Trying to get up to standards, here. Reading about project layout in
    Programming Ruby (3rd ed)., where reference is made to "...some strong
    Ruby conventions, first seen in Minero Aoki’s setup.rb and later
    enshrined in the Gems system...".

    One apparently expect to see in the project root a \bin, \lib, \doc,
    subdir, and quite possible a \db and \log and etc., subdirs.

    My question is about the \bin subdir. I was initially puzzled. How could
    a Ruby project have a binary files subdirectory? I went snooping in some
    installed gems I have, and I found very simple launch scripts in the
    \bin subdir - so far all ruby scripts, with the first line making clear
    that Ruby is to interpret the script (I'm also just getting into Bash
    tonight). OK, that all makes sense, except for the "\bin" name.

    So, in the Ruby world, \bin simply means "whatever I'm using to launch
    my program", if it's used at all, right? And "\bin" is simply an
    anachronism - has always been done that way?

    t.

    --

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
    Bellingham, Washington, U.S.A: (360) 920-1226
    << >> (email)
    << TomCloyd.com >> (website)
    << sleightmind.wordpress.com >> (mental health weblog)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tom Cloyd, Feb 14, 2009
    #1
    1. Advertising

  2. Tom Cloyd

    James Britt Guest

    Tom Cloyd wrote:

    > So, in the Ruby world, \bin simply means "whatever I'm using to launch
    > my program", if it's used at all, right? And "\bin" is simply an
    > anachronism - has always been done that way?


    Pretty much.

    If your app includes other command-line tools they would go in bin/ as
    well.

    --
    James Britt

    www.happycamperstudios.com - Wicked Cool Coding
    www.jamesbritt.com - Playing with Better Toys
    www.ruby-doc.org - Ruby Help & Documentation
    www.rubystuff.com - The Ruby Store for Ruby Stuff
    James Britt, Feb 14, 2009
    #2
    1. Advertising

  3. Tom Cloyd wrote:
    > So, in the Ruby world, \bin simply means "whatever I'm using to launch
    > my program", if it's used at all, right? And "\bin" is simply an
    > anachronism - has always been done that way?


    Right -- and it's not unique to Ruby either.

    From your use of backslashes, I'm guessing you're on Windows, so I can
    see your confusion. On Unix, quite often you find shell scripts in
    various bin directories. A few examples from my system: /bin/which,
    /usr/bin/git-svn, etc.

    I think the reason it's done this way is that once upon a time, most or
    all of the files in those system directories were binary executables.
    People probably started putting scripts there because it was already in
    the PATH anyway, and it makes sense -- in the above example, all the
    user really cares about is git-svn is another git command, so to be
    consistent, why not put all of Git together? Even if most commands are
    binary, but some are Perl scripts?

    So, in the Ruby world, bin is just "executables", binary or otherwise,
    as distinct from lib, where you would find library code. Both are ruby
    files, but bin/foo you might actually expect to set executable and run
    as a command, whereas if you did the same to lib/foo.rb, it probably
    wouldn't do anything.
    David Masover, Feb 14, 2009
    #3
  4. Tom Cloyd

    Tom Cloyd Guest

    David Masover wrote:
    > Tom Cloyd wrote:
    >> So, in the Ruby world, \bin simply means "whatever I'm using to
    >> launch my program", if it's used at all, right? And "\bin" is simply
    >> an anachronism - has always been done that way?

    >
    > Right -- and it's not unique to Ruby either.
    >
    > From your use of backslashes, I'm guessing you're on Windows, so I can
    > see your confusion. On Unix, quite often you find shell scripts in
    > various bin directories. A few examples from my system: /bin/which,
    > /usr/bin/git-svn, etc.
    >
    > I think the reason it's done this way is that once upon a time, most
    > or all of the files in those system directories were binary
    > executables. People probably started putting scripts there because it
    > was already in the PATH anyway, and it makes sense -- in the above
    > example, all the user really cares about is git-svn is another git
    > command, so to be consistent, why not put all of Git together? Even if
    > most commands are binary, but some are Perl scripts?
    >
    > So, in the Ruby world, bin is just "executables", binary or otherwise,
    > as distinct from lib, where you would find library code. Both are ruby
    > files, but bin/foo you might actually expect to set executable and run
    > as a command, whereas if you did the same to lib/foo.rb, it probably
    > wouldn't do anything.
    >
    >

    James, David, thanks! Just wanted to make sure I understood.

    Sad story: those backslashes were a slip. I've been off Windows for
    almost a year. It's been a long night, week, life. I'm tired. I was also
    trying to get past my first Bash script, and get Cucumber/RSpec based
    testing going, and I'm a bit boggled. For 15 min. I simply could NOT get
    a very simple bash script to launch 'cause I was invoking
    ".\script-name". When I finally caught the problem and flipped the
    backslash, I felt pretty foolish. Not the first time, though!

    t.

    --

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
    Bellingham, Washington, U.S.A: (360) 920-1226
    << >> (email)
    << TomCloyd.com >> (website)
    << sleightmind.wordpress.com >> (mental health weblog)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tom Cloyd, Feb 14, 2009
    #4
  5. Tom Cloyd

    7stud -- Guest

    Tom Cloyd wrote:
    >
    > ".\script-name". When I finally caught the problem and flipped the
    > backslash, I felt pretty foolish. Not the first time, though!
    >


    Back slashes are dangerous in strings because of all the escape
    sequences that can be used in strings. \s = space, so your command was
    interpreted as: ". cript-name". I'm guessing your system looked for a
    program named "." somewhere in your path, with the "cript-name" part
    being an arg for the "." program.
    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Feb 14, 2009
    #5
  6. David Masover wrote:
    ...
    > So, in the Ruby world, bin is just "executables", binary or otherwise,
    > as distinct from lib, where you would find library code. Both are ruby
    > files, but bin/foo you might actually expect to set executable and run
    > as a command, whereas if you did the same to lib/foo.rb, it probably
    > wouldn't do anything.


    Not just the ruby world.

    count = 0
    Dir['/usr/bin/*'].each do |fn|
    next if File.directory? fn
    File.open(fn) do |f|
    count += 1 if /^#!/ =~ f.read(100)
    end
    end
    p count # ==> 574

    Of course some of those are shell scripts that just execute a true
    "binary executable".

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, Feb 14, 2009
    #6
  7. 7stud -- wrote:
    > Tom Cloyd wrote:
    >
    >> ".\script-name". When I finally caught the problem and flipped the
    >> backslash, I felt pretty foolish. Not the first time, though!
    >>
    >>

    >
    > Back slashes are dangerous in strings because of all the escape
    > sequences that can be used in strings. \s = space, so your command was
    > interpreted as: ". cript-name". I'm guessing your system looked for a
    > program named "." somewhere in your path, with the "cript-name" part
    > being an arg for the "." program.
    >


    If that were the case, '.' is an alias for 'source', which means it
    would've taken a file called 'cript-name' in the current directory and
    executed it.

    On the other hand, if those quotes were included, it would actually be
    looking for a program named '. cript-name', as spaces are allowed in
    filenames...
    David Masover, Feb 14, 2009
    #7
  8. Tom Cloyd

    Tom Cloyd Guest

    David Masover wrote:
    > 7stud -- wrote:
    >> Tom Cloyd wrote:
    >>
    >>> ".\script-name". When I finally caught the problem and flipped the
    >>> backslash, I felt pretty foolish. Not the first time, though!
    >>>
    >>>

    >>
    >> Back slashes are dangerous in strings because of all the escape
    >> sequences that can be used in strings. \s = space, so your command
    >> was interpreted as: ". cript-name". I'm guessing your system looked
    >> for a program named "." somewhere in your path, with the "cript-name"
    >> part being an arg for the "." program.
    >>

    >
    > If that were the case, '.' is an alias for 'source', which means it
    > would've taken a file called 'cript-name' in the current directory and
    > executed it.
    >
    > On the other hand, if those quotes were included, it would actually be
    > looking for a program named '. cript-name', as spaces are allowed in
    > filenames...
    >
    >

    Ah...so many ways to screw up. So little time.

    t.

    --

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
    Bellingham, Washington, U.S.A: (360) 920-1226
    << >> (email)
    << TomCloyd.com >> (website)
    << sleightmind.wordpress.com >> (mental health weblog)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tom Cloyd, Feb 15, 2009
    #8
  9. Tom Cloyd

    Tom Cloyd Guest

    Joel VanderWerf wrote:
    > David Masover wrote:
    > ...
    >> So, in the Ruby world, bin is just "executables", binary or
    >> otherwise, as distinct from lib, where you would find library code.
    >> Both are ruby files, but bin/foo you might actually expect to set
    >> executable and run as a command, whereas if you did the same to
    >> lib/foo.rb, it probably wouldn't do anything.

    >
    > Not just the ruby world.
    >
    > count = 0
    > Dir['/usr/bin/*'].each do |fn|
    > next if File.directory? fn
    > File.open(fn) do |f|
    > count += 1 if /^#!/ =~ f.read(100)
    > end
    > end
    > p count # ==> 574
    >
    > Of course some of those are shell scripts that just execute a true
    > "binary executable".
    >

    Yikes. You sure know how to make a point! Thanks for the demo.

    T.

    --

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
    Bellingham, Washington, U.S.A: (360) 920-1226
    << >> (email)
    << TomCloyd.com >> (website)
    << sleightmind.wordpress.com >> (mental health weblog)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tom Cloyd, Feb 15, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Spiewak
    Replies:
    3
    Views:
    3,124
    Rick Spiewak
    Aug 26, 2003
  2. RobertH
    Replies:
    1
    Views:
    704
    Steve C. Orr [MVP, MCSD]
    Nov 4, 2003
  3. NWx
    Replies:
    4
    Views:
    2,946
    Kevin Spencer
    Feb 19, 2004
  4. Eric
    Replies:
    4
    Views:
    695
    clintonG
    Dec 24, 2004
  5. Replies:
    1
    Views:
    556
    John Timney \(MVP\)
    Jun 19, 2006
Loading...

Share This Page