Archive

Archive for the ‘Ruby’ Category

New features for Java 7 . . . smells like Ruby

November 25th, 2009 john No comments

Here’s a blog post summarizing new features for Java 7:

http://code.joejag.com/2009/new-language-features-in-java-7/

The new features are:

  • Language support for collections (like Ruby . . . but apparently still no Hash literal — probably way too late to wedge that in)
  • Automatic resource management (like Ruby’s IO objects that yield a reference to a block . . . but looks far less general)
  • New type inference operator
  • Underscores in numeric literals (1_000_000) (like Ruby)
  • Strings in switch statements (like Ruby . . . but only for Strings, so no ‘case equals’ operator)
  • binary literals (like Ruby)
  • Simplified varargs
Categories: Ruby Tags:

gem of the week: cheat

October 13th, 2009 john No comments

A couple of weeks ago I mentioned the “cheat” gem which has a plethora of useful quick docs on various topics such as regular expressions. I breezed through the install — and fix for Ruby 1.9.1 — here it is, for the record:

gem install cheat
# NOTE: If you're on Linux or OS/X and have a standard install (rather than using the ruby_switch.sh script, you want to do sudo gem install cheat)

If you run it under 1.9.x, you should get an error like so:

cheat regexp
/Users/jnorman/.gem/ruby/1.9.1/gems/cheat-1.2.1/lib/cheat.rb:150:in `cache_dir': uninitialized constant Cheat::PLATFORM (NameError)
	from /Users/jnorman/.gem/ruby/1.9.1/gems/cheat-1.2.1/lib/cheat.rb:16:in `sheets'
	from /Users/jnorman/.gem/ruby/1.9.1/gems/cheat-1.2.1/bin/cheat:4:in `<top (required)>'
	from /Users/jnorman/.gem/ruby/1.9.1/bin/cheat:19:in `load'
	from /Users/jnorman/.gem/ruby/1.9.1/bin/cheat:19:in `<main>'

What you want to do is edit the file producing the error (in my case, from the exception trace, /Users/jnorman/.gem/ruby/1.9.1/gems/cheat-1.2.1/lib/cheat.rb). Go to the line, and change the constant PLATFORM to RUBY_PLATFORM. Save the file.

And voila!

chelsea:~ jnorman$ cheat regexp
regexp:
  A regexp's form is written /pattern/modifiers where "pattern" is the regular
# much deleted

For help,

cheat cheat
Categories: Ruby, gems Tags:

Keeping projects small, code brevity

October 13th, 2009 john 2 comments

I know a number of you are interested in how Ruby and Rails seems to favor smaller projects, code brevity, and a general attitude of representational efficiency.

You might be interested in this new post by Ola Bini who discusses the claim that if a project is very big, you need all of the helps from a statically-typed language (such as Java).

http://olabini.com/blog/2009/10/plan-to-write-big-software-and-you-have-already-lost/

Categories: Ruby Tags: