Dash screenshotDash, by one man software shop Kapeli, is a nice little documentation browser and snippet manager for OSX. You can quickly look up methods by typing the method name in the little search field. But one thing that had me stumped for a bit was listing all available class instance methods.

Now this software is very new, it’s still currently a free release, but it will be priced once it gets it’s formal release. I assume there will also be some docs for it then, but in the meantime here’s a quick explanation through discovery.

I wanted to view all the instance methods for the Ruby String class. I tried to search for Ruby: String, which gave me a big list of methods that return a String. I tried a known String instance method, downcase, clicked the search result, and got the listing of Ruby’s String instance methods. Success, but in an ugly way.

Dash screenshot arrowA much better way is to just enter string in the search field, you then get a list of class names and methods on the top left. The top result should be the String class, but not necessarily from the documentation set you want. Click the little icon to the left of the class name, or hit <enter>. You’ll see a lit of docsets popup. Select the one you want. And that’s it. Simple, but hung me up for 10 minutes, I hope this saves someone else the trouble.

Dash docset popup

And a follow up. Steve Ringo (@stevenringo) pointed out that I was sooo close with ‘Ruby: String’, ‘Ruby:String’ (no space) would have given me what I wanted straight up… Doh!

{ 0 comments }

OSX, pushd, popd, and cd -

by adrian on May 16, 2012

When I first started on this path I was a Windows user. Since my main interest was Rails, and the best Rails tools were all Mac based, I swapped over to Mac. One thing this has led to is that in addition to learning all the required web dev stuff, I also had to learn the console in OSX. Here’s one thing I’d seen ages ago and thought was usefull, but promptly forgot as I had more important things to remember at the time. Today I was watching a Destroy All Software screencast awas reminded of the terminal directory stack.

pushd and popd

If you’re traversing directories a fair bit in the terminal window, these commands are great for moving around and remembering where you were. It’s a mini stack that you can store directories in, or drop back to the previous directory path. For instance, if you’re in the following directory

~/Dropbox/org

and want to do something in another directory. You could just cd into the new directory, or you could push the current directory into the stack with

pushd .

navigate to your new directory, do whatever you want there, then to go back to your stored directory

popd

Of course, this can be expanded multiple times, and the stack can store many directories. If you want to just work with two directories, there’s a different option.

Toggling between directories

This is a real simple one. If you are in one directory, and you swap into another directory, you can toggle back to the previous directory using

cd -

issuing the same command again will toggle back, and so on. Here’s a quick example showing all three.

[~]$ cd play/wedisagree/
[wedisagree (master)]$ cd ../madelucky/app/
[app (master)]$ cd -
/Users/adrian/play/wedisagree
[wedisagree (master)]$ pushd .
~/play/wedisagree ~/play/wedisagree
[wedisagree (master)]$ cd ~/org
[org]$ popd
~/play/wedisagree
[wedisagree (master)]$ cd -
/Users/adrian/org
[org]$ cd -
/Users/adrian/play/wedisagree
[wedisagree (master)]$

{ 0 comments }

Ruby array uniq

May 13, 2012

Quick post tonight, cause it’s Sunday and late. Used a new standard object method today, and it’s kind of cute. Array#uniq returns a new array containing only the distinct members of an array – dropping any duplicate members. a = [’a', ‘b’, ‘c’, ‘d’, ‘d’, ‘e’, ‘f’, ‘g’, ‘g’, ‘g’, ‘h’]   puts a.to_s # [...]

Read the full article →

Ruby environmental global variables

May 12, 2012

Came across this little snippet today $*[0] After a bit of digging, I found out it means almost the same as ARGV[0] I say almost because, while I can’t find a practical difference, they are actually different types of objects. [Desktop]$ irb 1.9.3-p125 :001 > defined? $* => "global-variable" 1.9.3-p125 :002 > defined? ARGV => [...]

Read the full article →

Tinkerbin, like JSfiddle with SASS, HAML, and Coffeescript

May 11, 2012

I came across tinkerbin yesterday. It’s kind of a simplified version of JSfiddle. Simplified as in a simpler interface. Kind of as in, but it also supports SASS, HAML, and Coffeescript. SASS and HAML I totally get, though personally I don’t like HAML. But Coffeescript seems strange to me in this environment. There is no option [...]

Read the full article →

Method chaining and DRY

May 10, 2012

One long time conceptual issue I have had is how to reconcile DRY (Don’t Repeat Yourself) with method chaining being a code smell. For instance, say I have a facebook credit transaction that stores an orderID and a user ID with the transaction record. When I do a transaction, I receive an AJAX message back [...]

Read the full article →

CoffeeScript, GitHub Gists, and Pry console

May 9, 2012

After spending enough time with native JavaScript now, and having just scored a decent JavaScript contract, I decided today to take the plunge and learn CoffeeScript. I spent a fair bit of time with that. Seems like fun, and a relief to lose some of the syntactic crap JavaScript saddles you with! I also took [...]

Read the full article →

Ruby OptionParser for command line switches

May 8, 2012

Super quick post – I’m about to head off to a Rails meetup. I was looking into command line switches today, OptionParser looks to be the best way to handle this. Docs here. A super quick example while I was stuffing around.

Read the full article →

What’s the deal with File.expand_path in Ruby?

May 7, 2012

I’ve done a fair bit of Ruby dev since starting with the awesome online Ruby on Rails Tutorial by Michael Hartl, played around at writing Gems, and written a number of command line tools. But one thing I always seemed to copy/paste into files from somewhere, then just modify, is something similar to: File.expand_path("../views/#{template}", __FILE__) It always [...]

Read the full article →

Ruby and JavaScript github code reading group

May 6, 2012

Yesterday  I found out about a codereading group for Ruby and JavaScript opensource code on GitHub. I really like the potential in this, and it seems perfectly timed for me. That’s right, it’s all about me! I’ve taught myself Ruby/Rails/JavaScript and assorted other stuff via books and the wonderful internets. The three main areas I [...]

Read the full article →