Ruby Dir.glob mystery: Where are the FNM_xxx flags described? - ruby

Note: This has already been posted on Ruby Forum some weeks ago. I'm crossposting it here, because I didn't get any response so far
Dir.glob provides an optional parameter, usually referred as 'flags'.
Where can I find a documentation about what flags are possible?
The Ruby 2.0 docs just say that the flags are "the same as used in
File.fnmatch".
Looking up the documentation of File.fnmatch, I only find the
explanation that these are the "FNM_xxx" flags, which can be or'ed
together. I could however find no documentation about what FNM_xxx flags
exist.
Where is this described?

It's actually defined inside File::Constants, and thereby documented under the same.
Look it up with ri :
ri File::Constants
Or read the html doc : Module: File::Constants (Ruby 2.2.2).

Related

What does File.exists? do in Ruby?

So I was looking through the Ruby standard library docs on how to read a file when I found File.exists?, with this fascinating and illuminating description:
exists?(p1)
 
(A Google search turns up a similar amount of information)
It's a real method, as verified by attempting to call it and not getting an error. Based on a couple of quick tests, it seems to do the same thing as File.exist?.
Is this correct, or does it have some other behavior that I missed?
Also, as a side-question, why isn't it documented at all? Is it deprecated?
According to the Ruby 2.2.0 doc, this method is deprecated:
exists?(file_name) → true or false
Deprecated method. Don’t use.

toContainHtml() vs. toHaveHtml() in jasmine-jquery

In the jquery-jasmine documentation (I've listed the exact revision of the docs in case they change).
It describes:
toContainHtml(string)
expect($('<div><ul></ul><h1>header</h1></div>')).toContainHtml('<ul></ul>')
toHaveHtml(string)
expect($('<div><span></span></div>')).toHaveHtml('<span></span>')
When should I use toContainHtml() and when should I use toHaveHtml()? From the examples I can't tell the difference.
Judging by this ticket on jasmine-jquery's github page
toHaveHtml() is more exacting using a == check
Whereas toContainHtml() uses an indexOf() check.
However the example in the documentation doesn't really demonstrate this, so I'm still not certain.

Do you know an alternative ctags generator for Ruby

Exumerant Ctags does not work well with Ruby, you can see there are many hacks in the ruby.c code and basically it fails recognizing many cases. One of the most important is this bit:
class SomeModule::SomeClass
end
Ctags generates:
SomeModule someclass.rb /^class SomeModule::SomeClass$/;" c
which is wrong. The correct and expected entry is:
SomeClass someclass.rb /^class SomeModule::SomeClass$/;" c
This is very limiting. There are some patches for ctags available which does not work, e.g. https://github.com/xtao/overlay/blob/master/dev-util/ctags/files/ctags-5.5.4-ruby-classes.patch but looking on the ctags ruby codebase, this really needs complete rewrite.
So I have been playing with other option which is https://github.com/rdoc/rdoc-tags which works nicer, but it is slow. I mean really SLOW. Generating tags on my project is 2 seconds with ctags but one hour with this tool. Really.
I found one old project that was parsing Ruby on it's own and generating tags, but it was only for Ruby 1.8. It was slower than ctags, but not that bad.
So I am searching for some alternatives. Do you know about any other working ruby ctags generators which give you proper output and are fast?
Thanks!
Edit: I have found very nice project that works with Ruby 1.9+ and is accurate and fast. I recommend it:
https://github.com/tmm1/ripper-tags
Ripper-tags effort does solve everything described here. It is based on official Ruby parser which is also quite fast. https://github.com/tmm1/ripper-tags
gem install ripper-tags
cd your_project/
ripper-tags -R
It does also support Emacs as well.
Exuberant ctags out of the box doesn’t do a number of useful things:
It doesn’t deal with:
module A::B
It doesn’t tag (at least some of) the “operator” methods like ‘==’
It doesn’t support qualified tags, —type=+
It doesn’t output tags for constants or attributes.
Patch available, but it is only for version 5.5 and does not work anymore.
Other projects:
https://github.com/tmm1/ripper-tags (best option for Ruby 1.9+)
https://rubygems.org/gems/rdoc-tags (very slow but works with 1.8)
Source
Add following to your ~/.ctags
--regex-ruby=/(^|;)[ \t]*(class|module)[ \t]+([A-Z][[:alnum:]_]+(::[A-Z][[:alnum:]_]+)+)/\3/c,class,constant/
So you can:
deal with: module A::B
See more here: https://github.com/bltavares/dot-files/blob/master/ctags
A patch is available as of 2013-02
https://github.com/fishman/ctags (ctags patch for Ruby, including rspec)
the rspec tag generator will not properly recognize describe blocks that start with semicolor (:some-method), but other than that, it's great.
There is also https://github.com/eapache/starscope
It doesn't support the extended tag format (yet) but it does other things such as exporting cscope databases.

Is there a doc like perlguts/illguts for ruby?

I recently enjoied the illustrated perlguts as fun and easy way to see how things are implemented without the need to dig through sources and would love to read such documentation for ruby.
Perlguts provides some information on the workings of the Perl interpreter and describes how to use the Perl API. Illguts i an illustrated version of perlguts.
Are there similar docs for ruby?
Here is some stuff along those lines:
The Ruby Hacking Guide (old, but contains some of that nuts & bolts info)
http://dev-logger.blogspot.com/2008/06/ruby-internals-by-patrick-farley.html

Standard Library Reference for Ruby

I need a good reference for how to use standard Libraries in Ruby. Current libraries do not describe or give examples like say Java's. Yet this is where examples are much more needed (in Ruby), because I am not familiar with what the called method will yield! I am left with having to look at the source files every time, which seems inefficient. What is a good standard library reference... or am I just not understanding blocks yet?
I find myself bouncing around between the ruby core API on ruby-doc.org, googling for answers on random blogs, and spending time testing ideas in the interactive interpreter (irb). I haven't seen any other core reference documentation that I liked, but I do have a copy of The Ruby Way and its pretty decent.
Betweeen these four sources I can almost always find out how to solve the problem I'm working on.
Best of luck - ruby is fun, frustrating, and powerful.
There is the Ruby Standard Library documentation and sites like apidock. The Pickaxe book has a great reference towards the end. There's even a free version online, but it's quite out of date; to find the reference there, click Standard Library in the top-left frame.
Try GotAPI You'll be able to find the Ruby standard documentation and a whole lot of api docs there
Understanding blocks is pretty important, especially if you want to understand the Enumerable module. ruby-doc.org is usually all I need, but if I need a little more explanation I grab the PickAxe. You need the PickAxe, no question.
I am sorry , but again, i have to recommend ruby cookbook. (Already two times today)

Resources