Ruby Weekly News 19th - 25th March 2007


T

Tim Sutherland

Links are at http://www.rubyweeklynews.org/20070325.html

Ruby Weekly News 19th - 25th March 2007
=======================================

Ruby Weekly News takes a look at the week's discussions on the ruby-talk
mailing list (and its equivalents, the comp.lang.ruby newsgroup and Ruby
forum).

This edition is brought to you by Tim Sutherland and MenTaLguY.

Articles and Announcements
==========================

* Ruby Hoedown 2007 - the Ruby conference down south
----------------------------------------------------

Jeremy McAnally proudly announces Ruby Hoedown 2007, the first
regional Ruby conference in the Southern United States.

"Ruby Hoedown, a joint effort between Raleigh.rb, Atlanta.rb, and
myself, is going to be held at the Red Hat HQ in Raleigh, NC on August
10-11, 2007."

* Pledgie drive for Rubinius
----------------------------

Sam Smoot ("not a committer to the project, just really excited about
it") noticed the Rubinius developers are trying to raise some money
through a "Pledgie drive".
Rubinius is a next-generation virtual machine and compiler for Ruby.
Based loosely on the Smalltalk-80 `Blue Book' design, Rubinius will
provide a rich, high-performance environment for running Ruby code.

As this edition of the Ruby Weekly News was going out, they were over
halfway to the target of raising US$1000, with 11 days left for
pledges.

User Group News
===============

* Israel.rb is brought into existence!
--------------------------------------

Adam Fine: "I am pleased to announce that the Israeli Ruby Brigade has
been unleashed upon an unsuspecting world." The first meeting is on
April 6th.

* Mountain West Ruby Conference slides, keynote?
------------------------------------------------

Videos and presentation slides from the Mountain West Ruby Conference
2007 are being assembled. DVDs will be free for those who attended the
conference, available for purchase by others, and the videos will also
be uploaded to Google Video.

Threads
=======

Generating OOo-Calc charts with Ruby
------------------------------------

apanloco is thinking of using Ruby to generate OpenOffice.org Calc charts.
He's used the win32ole with Excel to do the same; can something similar be
done with OpenOffice?

Avdi Grimm: "Since the OO document format is an XML dialect, it should be
possible to generate the files directly with e.g. REXML."

Pulling text from elements with REXML
-------------------------------------

Paul Willis writes:

require 'rexml/document'
include REXML
file = File.new("Main_News.xml")
doc = Document.new(file)
root = doc.root
puts root.elements["NewsItem/NewsComponent/NewsComponent[1]/.../hl1"]

This gives "<hl1>Blueprint to cut emissions unveiled</hl1>", but how do
you get just the text inside the node?

Peter Szinek says the #text method does the trick; try

root.elements[...your stuff_here...].to_a.each {|e| puts e.text}

A different approach is suggested by Phrogz: use REXML's XPath support.

include REXML
doc = Document.new("<root><kid>hello</kid><kid>world</kid></root>")
p XPath.match( doc, '/root/kid/text()' )
#=> ["hello", "world"]

Are comments objects?
---------------------

Stephen Becker IV is interested in adding a #help method to his objects
for the sake of interactive use, and asks whether the comments for a Ruby
class are available via reflection.

The answer, of course, is no-Ruby comments are discarded by the parser.
However, Jonas Pfenniger points out that Mauricio Fernandez's fastri may
be the next best thing to reflection, and also that irb already provides a
builtin help primitive which displays the rdoc for an object or method.

irb(main):001:0> help 'Object#object_id'
------------------------------------------------------- Object#object_id
obj.__id__ => fixnum
obj.object_id => fixnum
------------------------------------------------------------------------
Returns an integer identifier for _obj_. The same number will be
returned on all calls to +id+ for a given object, and no two active
objects will share an id. +Object#object_id+ is a different concept
from the +:name+ notation, which returns the symbol id of +name+.
Replaces the deprecated +Object#id+.

=> nil

Regexp and Prime numbers
========================

ruby -wle "puts 'Prime' unless ('1' * ARGV[0].to_i) =~ /^1$|^(11+?)\1+$/" 1234

The above is a Ruby translation of a wonderful trick from the Perl
community. Credits to Neil Kandalgaonkar and Abigail for the originals.

Substitute 1234 with any number, and this command will tell you if it's
prime - using the regular expression engine!

(This is also a great illustration of how "regular expressions" in Perl,
Ruby and others are more powerful than regular expressions in
computational theory: Primes is a non-regular language.)

New Releases
============

oniguruma for ruby initial release
----------------------------------

Dizan Vasquez announces the first release of oniguruma bindings for Ruby
1.8. Oniguruma, developed primarily by K.Kosako, is the regular expression
engine used in Ruby 1.9.

With these new bindings, developers can "use the powerful features of
Oniguruma (named groups, look-behinds, etc.) without the need to upgrado
to Ruby 1.9 or to patch and recompile the stable version."

Rassmalog 3.2.0
---------------

Suraj Kurapati made several improvements to Rassmalog, "a static blog
engine based on RSS 2.0, YAML, and Textile".
It features an extensible blog formatting mechanism, easy configuration,
and automatic tagging, archiving, syntax coloring, and table of
contents.

Getopt::Declare 1.23
--------------------

gga announces version 1.23 of Getopt::Declare, a library for commandline
option parsing where valid options are specified in the form of annotated
help texts. For example:

require "Getopt/Declare"
args = Getopt::Declare.new(<<'EOF')

-q, --quiet quiet
-f, --files <files:if>... input files
-n, --number <num:n> a float number
-i, --integer <num:i> an integer number

EOF

p args['-q']
p args['-f']
p args.unused

1.23 is primarily a bugfix release.

main-0.0.1 - command line apps for the truly lazy
-------------------------------------------------

Ara T. Howard announces the release of main, another in his line of
codeforpeople libraries.

main is "a class factory and dsl for generation main programs real quick",
providing a unified framework for argument processing, environment
handling, help text, and many of the other grotty little bits you need to
deal with in order to write a classy commandline utility in Ruby.

fastthread 1.0
--------------

MenTaLguY announced fastthread 1.0, a C extension which provides optimized
versions of the synchronization primitives in Ruby stdlib's thread.rb,
replacing the existing Mutex, ConditionVariable, Queue, and SizedQueue
classes with its own implementation.

While the Ruby stdlib thread library was redone in 1.8.6 based on an
earlier version of fastthread, a couple critical bugs snuck in at that
time. Consequently, for those using Ruby 1.8.6, the newer version of the
fastthread gem is recommended as a hotfix.

Best practice when requiring fastthread from a library is as follows:

require 'thread'
begin
require 'fastthread'
rescue LoadError
end

This will allow your code to work on Ruby versions where fastthread is
unavailable or is simply unnecessary (e.g. under YARV or JRuby).

daapclient 0.2.3
----------------

Aaron Patterson announces version 0.2.3 of daapclient, a Ruby client for
the iTunes DAAP protocol. It contains log optimizations, a couple bug
fixes, and switches the build system to hoe.


end
===
We hoped you enjoyed this edition of the Ruby Weekly News.

Anyone can contribute to the next newsletter - simply visit
http://www.rubyweeklynews.org/newsletters/contribute/next to summarise
one or more threads from the list. Thanks!
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top