Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > The mystery of File::append

Reply
Thread Tools

The mystery of File::append

 
 
Nit Khair
Guest
Posts: n/a
 
      09-18-2008
$ ri File::append
gives me:

File::append( file, str )
------------------------------------------------------------------------
Append to a file.

CREDIT: George Moschovitis

`$ri File` also shows me append as a class method.

However, my html documentation does not give this (1.8.6). Trying to use
`File::append` in irb or ruby fails (no such method). Even google has no
entry for this class method.

What mistake am I making ?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Stefano Crocco
Guest
Posts: n/a
 
      09-18-2008
Alle Thursday 18 September 2008, Nit Khair ha scritto:
> $ ri File::append
> gives me:
>
> File::append( file, str )
> ------------------------------------------------------------------------
> Append to a file.
>
> CREDIT: George Moschovitis
>
> `$ri File` also shows me append as a class method.
>
> However, my html documentation does not give this (1.8.6). Trying to use
> `File::append` in irb or ruby fails (no such method). Even google has no
> entry for this class method.
>
> What mistake am I making ?


It's part of the facets library. Unfortunately, ri doesn't show the name of
the file where a method or class is defined or the library or gem it comes
from. To use that method, since it seems you already have facets installed,
you need to do this:

require 'rubygems' #unless it's already defined in the RUBYOPT environment
#variable
require 'facets/file/write'
File.append(file, str)

I hope this helps

Stefano


 
Reply With Quote
 
 
 
 
Nit Khair
Guest
Posts: n/a
 
      09-18-2008
Stefano Crocco wrote:
> It's part of the facets library. Unfortunately, ri doesn't show the name


Aah, thanks. Yes, I used facets last year...

However, would be grateful if you could tell me how to decide what to
use in the require statement for a facets class. Whenever i use facets,
i struggle to figure out the require statement. What is shown in the
examples often does not work.

Some while back I came upon ProgressBar. It took me a while of trying to
figure out the require.

Then Console::ANSICode gives an example: "include Console::ANSICode"

irb(main):011:0> include Console::ANSICode
NameError: uninitialized constant Console
from (irb):11

I tried many combinations, finally "require 'facets/ansicode'" did not
give an error but still the "include Console::ANSICode" gives the error
above.
I can't remember if I managed to make the example run or not.

(I have started with require rubygems and facets.)
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Stefano Crocco
Guest
Posts: n/a
 
      09-18-2008
Alle Thursday 18 September 2008, Nit Khair ha scritto:
> Stefano Crocco wrote:
> > It's part of the facets library. Unfortunately, ri doesn't show the name

>
> Aah, thanks. Yes, I used facets last year...
>
> However, would be grateful if you could tell me how to decide what to
> use in the require statement for a facets class. Whenever i use facets,
> i struggle to figure out the require statement. What is shown in the
> examples often does not work.
>
> Some while back I came upon ProgressBar. It took me a while of trying to
> figure out the require.
>
> Then Console::ANSICode gives an example: "include Console::ANSICode"
>
> irb(main):011:0> include Console::ANSICode
> NameError: uninitialized constant Console
> from (irb):11
>
> I tried many combinations, finally "require 'facets/ansicode'" did not
> give an error but still the "include Console::ANSICode" gives the error
> above.
> I can't remember if I managed to make the example run or not.
>
> (I have started with require rubygems and facets.)


According to the facets documentation, a simple

require 'facets'

will require all the Core facets library. If you want to load only the Core
methods for a single class (for example, the File class), you can do

require 'facets/file'

If you want only to load a specific method, you can find the file where it's
defined by looking up the method you're interested to in the facets rdoc api
(http://facets.rubyforge.org/doc/index.html), then clicking on the "show
source" link. This will display the source code for the method. At the top of
the source code, there's a comment with the name of the file where the method
is defined. This is the file you need to require. Note, however, that that
line starts with something like 'lib/core/facets/.../'. You should only put
the part of the string starting with facets in your call to require.

All what I said is valid for recent versions of facets, so if you have an old
version, you may need to update it.

Stefano

Stefano



 
Reply With Quote
 
Trans
Guest
Posts: n/a
 
      09-18-2008


On Sep 18, 3:27=A0am, Nit Khair <(E-Mail Removed)> wrote:
> Stefano Crocco wrote:
> > It's part of the facets library. Unfortunately, ri doesn't show the nam=

e
>
> Aah, thanks. Yes, I used facets last year...
>
> However, would be grateful if you could tell me how to decide what to
> use in the require statement for a facets class. Whenever i use facets,
> i struggle to figure out the require statement. What is shown in the
> examples often does not work.


It is:

require 'facets/{class|module}/{method_name}'

There are some exceptions where one method is in the same file as
another (eg. write/append), but these are being worked out and should
be almost not existent in another release or two. Even so, require
'facets' hides all that.

> Some while back I came upon ProgressBar. It took me a while of trying to
> figure out the require.
>
> Then Console::ANSICode gives an example: "include Console::ANSICode"
>
> irb(main):011:0> =A0 include Console::ANSICode
> NameError: uninitialized constant Console
> =A0 from (irb):11


It's just

require 'facets/ansicode'

ANSICode

The Console:: namespace has been deprecated. The docs just need to be
fixed.

T.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mystery Bill McCarty Firefox 10 05-27-2005 04:35 AM
wifi mystery Txl Wireless Networking 4 03-25-2005 06:28 PM
Mystery frame below status bar [Xandros Bus 2/Firefox 1.0] John Bartley Firefox 1 03-23-2005 04:01 PM
Mystery # 2 Bill McCarty Firefox 5 01-02-2005 06:07 PM
Mystery Bill McCarty Firefox 5 12-31-2004 10:57 PM



Advertisments