Ruby: October 2008 Archives

Hoe is a simple rake/rubygems helper for project Rakefiles. It generates all the usual tasks for projects including rdoc generation, testing, packaging, and deployment.

Tasks Provided:

  • announce - Create news email file and post to rubyforge.
  • audit - Run ZenTest against the package.
  • check_manifest - Verify the manifest.
  • clean - Clean up all the extras.
  • config_hoe - Create a fresh ~/.hoerc file.
  • debug_gem - Show information about the gem.
  • default - Run the default tasks.
  • deps:email - Print a contact list for gems dependent on this gem
  • deps:fetch - Fetch all the dependent gems of this gem into tarballs
  • deps:list - List all the dependent gems of this gem
  • docs - Build the docs HTML Files
  • email - Generate email announcement file.
  • gem - Build the gem file hoe-1.8.0.gem
  • generate_key - Generate a key for signing your gems.
  • install_gem - Install the package as a gem.
  • multi - Run the test suite using multiruby.
  • package - Build all the packages
  • post_blog - Post announcement to blog.
  • post_news - Post announcement to rubyforge.
  • publish_docs - Publish RDoc to RubyForge.
  • release - Package and upload the release to rubyforge.
  • ridocs - Generate ri locally for testing.
  • tasks - Generate a list of tasks for doco.
  • test - Run the test suite.
  • test_deps - Show which test files fail when run alone.

See class rdoc for help. Hint: ri Hoe

Changes:

1.8.2 / 2008-10-24:

Inline allows you to write foreign code within your ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.

You can even write extra builders that will allow you to write inlined code in any language. Use Inline::C as a template and look at Module#inline for the required API.

Changes:

3.8.1 / 2008-10-24

ParseTree is a C extension (using RubyInline) that extracts the parse tree for an entire class or a specific method and returns it as a s-expression (aka sexp) using ruby's arrays, strings, symbols, and integers.

As an example:

def conditional1(arg1) if arg1 == 0 then return 1 end return 0 end

becomes:

[:defn, :conditional1, [:scope, [:block, [:args, :arg1], [:if, [:call, [:lvar, :arg1], :==, [:array, [:lit, 0]]], [:return, [:lit, 1]], nil], [:return, [:lit, 0]]]]]

Changes:

3.0.1 / 2008-10-23

Flog reports the most tortured code in an easy to read pain report. The higher the score, the more pain the code is in.

Changes:

1.2.0 / 2008-10-22

  • 14 minor enhancements:

    • Added -c flag to continue dispite errors.
    • Added -m to only report code in methods (skips #none).
    • Added -n flag to give NO method details (summary only)
    • Added -n to skip method details... pussies should learn grep.
    • Added -q to quiet method details (total per method only)
    • Added avg & stddev to total.
    • Added avg score per method to report.
    • Added lots of doco from contributors (hugh sasse?).
    • Fixed class names when const2/3.
    • Fixed unified ruby changes
    • Refactored flog with help from flay.
    • Refactored getsourceindex
    • Refactored into gem_updater.rb and cleaned up.
    • Works with new incremental rubygems, albiet slower than before.
  • http://ruby.sadi.st/

  • http://rubyforge.org/projects/seattlerb

ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc--which does by default use a C extension). RP's output is the same as ParseTree's output: s-expressions using ruby's arrays and base types.

Changes:

2.0.0 / 2008-10-22

  • 1 major enhancement

    • Brought on the AWESOME! 4x faster! no known lexing/parsing bugs!
  • 71 minor enhancements

    • 1.9: Added Fixnum#ord.
    • 1.9: Added missing Regexp constants and did it so it'd work on 1.9.
    • Added #store_comment and #comments
    • Added StringScanner #beginofline?
    • Added a bunch of tests for regexp escape chars, #parsestring, #readescape, ? numbers, ? whitespace.
    • Added a hack for rubinius' r2l eval bug.
    • Added a new token type tSTRING that bypasses tSTRING_BEG/END entirely. Only does non-interpolated strings and then falls back to the old way. MUCH cleaner tho.
    • Added bin/ruby_parse
    • Added compare rule to Rakefile.
    • Added coverage files/dirs to clean rule.
    • Added file and line numbers to all sexp nodes. Column/ranges to come.
    • Added lex_state change for lvars at the end of yylex.
    • Added lexed comments to defn/defs/class/module nodes.
    • Added stats gathering for yylex. Reordered yylex for avg data
    • Added tSYMBOL token type and parser rule to speed up symbol lexing.
    • Added tally output for getch, unread, and unread_many.
    • Added tests for ambigous uminus/uplus, backtick in cmdarg, square and curly brackets, numeric gvars, eos edge cases, string quoting %<> and %%%.
    • All cases throughout yylex now return directly if they match, no passthroughs.
    • All lexer cases now slurp entire token in one swoop.
    • All zarrays are now just empty arrays.
    • Changed s(:block_arg, :blah) to :"&blah" in args sexp.
    • Cleaned up lexer error handling. Now just raises all over.
    • Cleaned up readescape and regxoptions
    • Cleaned up tokadd_string (for some definition of cleaned).
    • Converted single quoted strings to new tSTRING token type.
    • Coverage is currently 94.4% on lexer.
    • Done what I can to clean up heredoc lexing... still sucks.
    • Flattened resbodies in rescue node. Fixed .autotest file.
    • Folded lex_keywords back in now that it screams.
    • Found very last instanceof ILiteralNode in the code. haha!
    • Got the tests subclassing PTTC and cleaned up a lot. YAY
    • Handle yield(*ary) properly
    • MASSIVELY cleaned out =begin/=end comment processor.
    • Massive overhaul on Keyword class. All hail the mighty Hash!
    • Massively cleaned up ident= edge cases and fixed a stupid bug from jruby.
    • Merged @/@@ scanner together, going to try to do the same everywhere.
    • Refactored fixarglex_state, common across the lexer.
    • Refactored newfcall into newcall.
    • Refactored some code to get better profile numbers.
    • Refactored some more #fixarglex_state.
    • Refactored tail of yylex into its own method.
    • Removed Module#kill
    • Removed Token, replaced with Sexp.
    • Removed all parsenumber and parsequote tests.
    • Removed argspush, argscat. YAY!
    • Removed as many token_buffer.split(//)'s as possible. 1 to go.
    • Removed begins from compstmts
    • Removed buffer arg for tokadd_string.
    • Removed crufty (?) solo '@' token... wtf was that anyhow?
    • Removed most jruby/stringio cruft from StringScanner.
    • Removed one unread_many... 2 to go. They're harder.
    • Removed store_comment, now done directly.
    • Removed token_buffer. Now I just use token ivar.
    • Removed use of s() from lexer. Changed the way line numbers are gathered.
    • Renamed *qwords to *awords.
    • Renamed StringScanner to RPStringScanner (a subclass) to fix namespace trashing.
    • Renamed parse to process and aliased to parse.
    • Renamed tokenbuffer to stringbuffer since that arcane shit still needs it.
    • Resolved the rest of the lexing issues I brought up w/ ruby-core.
    • Revamped tokadd_escape.
    • Rewrote Keyword and KWtable.
    • Rewrote RubyLexer using StringScanner.
    • Rewrote tokadd_escape. 79 lines down to 21.
    • Split out lib/rubyparserextras.rb so lexer is standalone.
    • Started to clean up the parser and make it as skinny as possible
    • Stripped out as much code as possible.
    • Stripped yylex of some dead code.
    • Switched from StringIO to StringScanner.
    • Updated rakefile for new hoe.
    • Uses pure ruby racc if ENV['PURE_RUBY'], otherwise use c.
    • Wrote a ton of lexer tests. Coverage is as close to 100% as possible.
    • Wrote args to clean up the big nasty args processing grammar section.
    • lex_strterm is now a plain array, removed RubyLexer#s(...).
    • yield and super now flatten args.
  • 21+ bug fixes:

    • I'm sure this list is missing a lot:
    • Fixed 2 bugs both involving attrasgn (and ilk) esp when lhs is an array.
    • Fixed a bug in the lexer for strings with single digit hex escapes.
    • Fixed a bug parsing: a (args) { expr }... the space caused a different route to be followed and all hell broke loose.
    • Fixed a bug with x\n=beginvar not putting begin back.
    • Fixed attrasgn to have arglists, not arrays.
    • Fixed bug in defn/defs with block fixing.
    • Fixed class/module's name slot if colon2/3.
    • Fixed dstr with empty interpolation body.
    • Fixed for 1.9 string/char changes.
    • Fixed lexer BS wrt determining token type of words.
    • Fixed lexer BS wrt pass through values and lexing words. SO STUPID.
    • Fixed lexing of floats.
    • Fixed lexing of identifiers followed by equals. I hope.
    • Fixed masgn with splat on lhs
    • Fixed newsuper to deal with blockpass correctly.
    • Fixed parser's treatment of :colon2 and :colon3.
    • Fixed regexp scanning of escaped numbers, ANY number is valid, not just octs.
    • Fixed string scanning of escaped octs, allowing 1-3 chars.
    • Fixed unescape for \n
    • Fixed: omg this is stupid. '()' was returning bare nil
    • Fixed: remove_begin now goes to the end, not sure why it didn't before.

FIX (describe your package)

Changes:

3.0.0 / 2008-10-22

  • 2 major enhancements:

    • Released as its own project, splitting from ParseTree
    • Added Environment to SexpProcessor and built it in. YAY!
  • 6 minor enhancements:

    • Allowed CompositeSexpProcessor to be more ducktypey.
    • Refactored Sexp#methodmissing into findnode and find_nodes.
    • Removed Sexp#for and other PT specific code.
    • SexpProcessor#process now runs rewriters before everything else.
    • SexpProcessor#rewrite context only for subs, EMPTY for top level rewrites.
    • SexpProcessor#rewrite will stop iterating if the result isn't another Sexp.

ruby2ruby provides a means of generating pure ruby code easily from ParseTree's Sexps. This makes making dynamic language processors much easier in ruby than ever before.

Changes:

1.2.0 / 2008-10-22

ParseTree is a C extension (using RubyInline) that extracts the parse tree for an entire class or a specific method and returns it as a s-expression (aka sexp) using ruby's arrays, strings, symbols, and integers.

As an example:

def conditional1(arg1) if arg1 == 0 then return 1 end return 0 end

becomes:

[:defn, :conditional1, [:scope, [:block, [:args, :arg1], [:if, [:call, [:lvar, :arg1], :==, [:array, [:lit, 0]]], [:return, [:lit, 1]], nil], [:return, [:lit, 0]]]]]

Changes:

3.0.0 / 2008-10-22

  • 3 major enhancements:

    • Split out sexp_processor project.
    • ParseTree#process outputs a UnifiedRuby parse tree.
    • Switched all ParseTree tests to RawParseTree tests.
    • Added ParseTree tests.
    • Added UnifiedRuby#process.
  • 28 minor enhancements:

    • PTTC: Added a comprehensive suite of tests for every combo of defn args.
    • PTTC: Added a ton of new tests.
    • PTTC: Added extra tests for mri verbose flag testing (horrid horrid bug imhfo)
    • PTTC: Don't generate tests if class has "TestCase" in the class name.
    • PTTC: Made self.previous more overridable.
    • PTTC: Now all tests that have "mriverboseflag" activate $VERBOSE
    • PTTC: Officially added clonesame phase to generatetests
    • PTTC: Refactored test generation to make subclasses more flexible.
    • PTTC: Refactored to use new add_tests. Much much cleaner.
    • PTTC: Removed Unique from PTTC... subclasses need to deal with this
    • PTTC: Removed some stupid tests.
    • PTTC: Renamed a bunch of tests to be more uniform.
    • UR: Added rewrite_attrasgn to normalize arg array into arglist.
    • UR: Added rewriteopasgn1 to ensure the arglist is an arglist.
    • UR: Flattened resbodies in rescue node.
    • UR: Flattened super and yield args yet, deal with array arg properly.
    • UR: Handle yield(*ary) properly.
    • UR: Nuked argspush.
    • UR: Removed begin node from unified sexps.
    • UR: Removed block from rewritten resbody if only 1 element.
    • UR: Removed dasgn, dasgn_curr, and dvar nodes.
    • UR: Removed s(:block_arg, :block) in favor of :"&block"
    • UR: Rewrote argscat to be a splat inside an array.
    • UR: Rewrote block_pass into arglist of inner call/super.
    • UR: Rewrote call to ALWAYS have an argslist (no more splat as arglist).
    • UR: Rewrote rewrite_resbody from scratch... MUUCH cleaner.
    • UR: zarray -> array
    • Used Hoe#addincludedirs to clean up rakefile.
    • Moved PT dependent code from ruby2ruby to here (eg Proc#to_sexp & friends).
  • 2 bug fixes:

    • UR: Fixed a bug with resbody that starts with an lasgn.
    • UR: Fixed args for attrset
    • Fixed export of symbols to work across platforms.
  • http://rubyforge.org/projects/parsetree/

  • http://www.zenspider.com/ZSS/Products/ParseTree/
  • ryand-ruby@zenspider.com

Inline allows you to write foreign code within your ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.

You can even write extra builders that will allow you to write inlined code in any language. Use Inline::C as a template and look at Module#inline for the required API.

Changes:

3.8.0 / 2008-10-22

ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails.

ZenTest scans your target and unit-test code and writes your missing code based on simple naming rules, enabling XP at a much quicker pace. ZenTest only works with Ruby and Test::Unit.

unit_diff is a command-line filter to diff expected results from actual results and allow you to quickly see exactly what is wrong.

autotest is a continous testing facility meant to be used during development. As soon as you save a file, autotest will run the corresponding dependent tests.

multiruby runs anything you want on multiple versions of ruby. Great for compatibility checking! Use multiruby_setup to manage your installed versions.

Test::Rails helps you build industrial-strength Rails code.

Changes:

3.11.0 / 2008-10-22

  • 19 minor enhancements:

    • Added :updated hook, gets list of updated files before running tests.
    • Added autotest/restart.rb - restarts autotest if .autotest updated.
    • Added better help to multiruby.
    • Added dummy build command to multiruby_setup.
    • Added git support.
    • Added rbx:ln:$dir and rbx:git:current.
    • Added rubygems:merge as a nice little hack to share rubygems setups.
    • Added svn tag updating (eg will svn sw from mri 1.8.6 222 to 1.8.6 231).
    • Autotest hooks now take *args as well as instance of autotest.
    • Made it possible to have manually specified tags.
    • Made multiruby a little more self-repairing wrt symlinks and build dirs.
    • Refactored into mrilatesttag(v).
    • Refactored unit_diff to make it a bit easier to use as a library.
    • Refactored zentest mapping main methods into munge/unmunge.
    • Removed rubinius specific symlink hacks, now fully supported.
    • mri:svn:releases figures out all the latest patch levels.
    • multiruby_setup clean now checks for rakefile first, since rbx has both. :(
    • multiruby_setup help now exits instead of building.
    • multiruby_setup list and clean now exit
  • 2 bug fixes:

    • ZenTestMapping converts operator prefixes to operators only when an _ follows.
    • Apparently Tempfile.open doesn't return it's last value. fixed.
  • 2 bug fixes:

    • Fixed bug in mri:svn:branch:xxx with svn dir name.
    • multiruby_setup rm now smarter about tarballs.
  • http://www.zenspider.com/ZSS/Products/ZenTest/

  • http://rubyforge.org/projects/zentest/
  • ryand-ruby@zenspider.com

A script which automates a limited set of rubyforge operations.

  • Run 'rubyforge help' for complete usage.
  • Setup: For first time users AND upgrades to 0.4.0:
    • rubyforge setup (deletes your username and password, so run sparingly!)
    • edit ~/.rubyforge/user-config.yml
    • rubyforge config
  • For all rubyforge upgrades, run 'rubyforge config' to ensure you have latest.
  • Don't forget to login! logging in will store a cookie in your .rubyforge directory which expires after a time. always run the login command before any operation that requires authentication, such as uploading a package.

Changes:

1.0.1 / 2008-10-22:

Hoe is a simple rake/rubygems helper for project Rakefiles. It generates all the usual tasks for projects including rdoc generation, testing, packaging, and deployment.

Tasks Provided:

  • announce - Create news email file and post to rubyforge.
  • audit - Run ZenTest against the package.
  • check_manifest - Verify the manifest.
  • clean - Clean up all the extras.
  • config_hoe - Create a fresh ~/.hoerc file.
  • debug_gem - Show information about the gem.
  • default - Run the default tasks.
  • deps:email - Print a contact list for gems dependent on this gem
  • deps:fetch - Fetch all the dependent gems of this gem into tarballs
  • deps:list - List all the dependent gems of this gem
  • docs - Build the docs HTML Files
  • email - Generate email announcement file.
  • gem - Build the gem file hoe-1.8.0.gem
  • generate_key - Generate a key for signing your gems.
  • install_gem - Install the package as a gem.
  • multi - Run the test suite using multiruby.
  • package - Build all the packages
  • post_blog - Post announcement to blog.
  • post_news - Post announcement to rubyforge.
  • publish_docs - Publish RDoc to RubyForge.
  • release - Package and upload the release to rubyforge.
  • ridocs - Generate ri locally for testing.
  • tasks - Generate a list of tasks for doco.
  • test - Run the test suite.
  • test_deps - Show which test files fail when run alone.

See class rdoc for help. Hint: ri Hoe

Changes:

1.8.1 / 2008-10-22

Crazy Singleton Methods

| | Comments (0)

So, just about everyone knows about singleton methods... it means you can attach a method to a single individual object. Most often this is used for class methods:

class Person
  def self.people
    # return all people
  end
end

Which is fine, but you can also do things to any old instance:

a = "string!"
def a.inspect
  ":symbol!"
end
p a
# => :symbol!

What I didn't know and learned while working on rubyparser is that there is another kind of singleton. The above singleton is a _variable-based singleton. It requires a variable as the target for the singleton definition.

For example, you can't do this:

a = Object.new
class Object ; def b; end end
def a.b.x ; 42; end
SyntaxError: compile error
(irb):8: syntax error, unexpected '.', expecting '\n' or ';'
def a.b.x ; 42; end
        ^
(irb):8: syntax error, unexpected kEND, expecting $end

BUT! Looking at the grammar, you can do singletons w/ any expression by using parenthesis! Here is an expression-based singleton:

def (a.b).x ; 42; end
a.b.x
# => 42

Now, the above example is crap... but maybe you'd want to do something like:

class Agent
  @@tasks = []
  def self.spawn
    t = Task.new
    @@tasks << t
    t
  end
end

def (Agent.spawn).task
  puts "YAY!"
end

No... I still can't see why you'd want to... but you can.

minitestteshim bridges the gap between the small and fast minitest and ruby's huge and slow test/unit.

Changes:

1.3.0 / 2008-10-09

minitest/unit is a small and fast replacement for ruby's huge and slow test/unit. This is meant to be clean and easy to use both as a regular test writer and for language implementors that need a minimal set of methods to bootstrap a working unit test suite.

mini/spec is a functionally complete spec engine.

mini/mock, by Steven Baker, is a beautifully tiny mock object framework.

(This package was called miniunit once upon a time)

Changes:

1.3.0 / 2008-10-09

  • 2 major enhancements:

    • renamed to minitest and pulled out test/unit compatibility.
    • mini/test.rb is now minitest/unit.rb, everything else maps directly.
  • 12 minor enhancements:

    • assert_match now checks that act can call =~ and converts exp to a regexp only if needed.
    • Added assert_send... seems useless to me tho.
    • message now forces to string... ruby-core likes to pass classes and arrays :(
    • Added -v handling and switched to @verbose from $DEBUG.
    • Verbose output now includes test class name and adds a sortable running time!
    • Switched message generation into procs for message deferment.
    • Added skip and renamed fail to flunk.
    • Improved output failure messages for assertinstanceof, assertkindof
    • Improved output for assertrespondto, assert_same.
    • at_exit now exits false instead of errors+failures.
    • Made the tests happier and more readable imhfo.
    • Switched index(s) == 0 to rindex(s, 0) on nobu's suggestion. Faster.
  • 5 bug fixes:

    • 1.9: Added encoding normalization in mu_pp.
    • 1.9: Fixed backtrace filtering (BTs are expanded now)
    • Added back exceptiondetails to assertraises. DOH.
    • Fixed shadowed variable in mock.rb
    • Fixed stupid muscle memory message bug in assert_send.
  • http://rubyforge.org/projects/bfts

Hoe is a simple rake/rubygems helper for project Rakefiles. It generates all the usual tasks for projects including rdoc generation, testing, packaging, and deployment.

Tasks Provided:

  • announce - Create news email file and post to rubyforge.
  • audit - Run ZenTest against the package.
  • check_manifest - Verify the manifest.
  • clean - Clean up all the extras.
  • config_hoe - Create a fresh ~/.hoerc file.
  • debug_gem - Show information about the gem.
  • default - Run the default tasks.
  • deps:email - Print a contact list for gems dependent on this gem
  • deps:fetch - Fetch all the dependent gems of this gem into tarballs
  • deps:list - List all the dependent gems of this gem
  • docs - Build the docs HTML Files
  • email - Generate email announcement file.
  • gem - Build the gem file hoe-1.8.0.gem
  • generate_key - Generate a key for signing your gems.
  • install_gem - Install the package as a gem.
  • multi - Run the test suite using multiruby.
  • package - Build all the packages
  • post_blog - Post announcement to blog.
  • post_news - Post announcement to rubyforge.
  • publish_docs - Publish RDoc to RubyForge.
  • release - Package and upload the release to rubyforge.
  • ridocs - Generate ri locally for testing.
  • tasks - Generate a list of tasks for doco.
  • test - Run the test suite.
  • test_deps - Show which test files fail when run alone.

See class rdoc for help. Hint: ri Hoe

Changes:

1.8.0 / 2008-10-09

I'm about to put out a flood of releases, several of which are "dot-ohs" and are not fully backwards compatible. In doing so, I knew that projects dependent on my projects (including some of my own) might break. Here is how to avoid that scenario.

Here is ParseTree's dependencies and dependents:

ParseTree:
  dependencies:
    RubyInline-3.7.0          >= 3.6.0
    hoe-1.7.0                 >= 1.5.3
  dependents:
    RubyToC-1.0.0.5            > 0.0.0
    SuperCaller-1.0.0         ~> 2.0
    ZenHacks-1.0.1             > 0.0.0
    ambition-0.5.2             = 2.0.1
    argible-0.1.1             >= 2.0.0
    flog-1.1.0                >= 2.0.0
    merb-action-args-0.9.7    >= 2.2
    protocol-0.8.0            >= 2.0.2
    red-3.5.0                 >= 2.2.0
    reek-0.2.3                >= 2.2.0
    rogue_parser-1.0.1        >= 0
    roodi-1.3.0               >= 0
    ruby2ruby-1.1.9           >= 0
    ruby_diff-0.1.5           >= 2.0.2
    ruby_parser-1.0.0         >= 0
    rubyjs-0.8.0              >= 2.1.1
    sake-1.0.15                = 2.1.1
    scrubyt-0.3.4              = 1.7.1
    thorero-action-args-0.9.4 >= 2.2

Now, let's say I put out RubyInline 4.0.0 and it isn't fully backwards compatible with RubyInline 3.x.y. What happens? Well, anyone installing ParseTree or otherwise updating their gems will update RubyInline and their ParseTree will break. Why? Because the version specifier for RubyInline is ">=" and 4.0.0 is just fine with that.

What I should have done was specify "~> 3.0". That lets me flexibly set a range of dependencies but does not go up to the next major release. By extension, every single dependency on ParseTree listed above is going to break except SuperCaller.

Here is how the dependency specifiers work:

Version Specification
3 and up, ">= 3"
3.y.z, "~> 3.0"
3.0.z, "~> 3.0.0"
3.5.z to <4.0 "~> 3.5"
3.5.z to <3.6 "~> 3.5.0"

So, armed with that, make sure that from here on out you specify your dependencies with "~>" and catastrophe won't visit your doorstep.

P.S. I'm about to directly email all the authors of projects dependent on my upcoming releases to warn them... Hopefully we can mop all this up quickly.

About this Archive

This page is a archive of entries in the Ruby category from October 2008.

Ruby: September 2008 is the previous archive.

Ruby: November 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Pages

Powered by Movable Type 4.1