The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
User-Defined Literals in Sydney

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
User-Defined Literals in Sydney Posted: Jul 13, 2005 11:21 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: User-Defined Literals in Sydney
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

Evan’s just released another Sydney while the Ruby-Core list is alive with bug reports and input from the core team. Nobu spotted a problem with user-defined literals and I was like, “oh, right, I need to try that.”

Add your methods to the PercentExpansion module. So, if you want your own %y, do like:

 require 'yaml'
 module PercentExpansion
   def y( str, m ); YAML::load( str ) end
 end

 METADATA = %y{
   author: _why
   date: 2005-07-13 09:10:12 -05:00
   title: User-defined Literals
 }

Or for fetching a URI:

 require 'open-uri'
 module PercentExpansion
   def fetch( str, m )
     URI.parse( str ).open do |urif|
       urif.read
     end
   end
 end

 ruby_terms = %fetch{http://ruby-lang.org/en/LICENSE.txt}

Sydney bars you from overriding the default literals. Which is probably safe. But, you know, I have to wonder what sort of hacks we’d see if these could be overridden.

Or if the string itself could be overturned. One thought: interpolation could be restyled in midair. R is for recklesssnessss.

Read: User-Defined Literals in Sydney

Topic: Odeo launched to the public Previous Topic   Next Topic Topic: Odeo Opens the Doors

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use