Ruby

Basic string manipulation in ruby

March 23rd, 2011

Split string to an array

One common task that you probably want to learn how to do is spliting a string into an array (like explode function in PHP). You can do this by calling “split” method. By default it will split a string on whitespace, but you can pass it a delimiter. Delimiter can be a string or regular expression.

1
2
3
4
5
6
7
animals = 'dog wolf cat lynx tiger'
animals.split # => ["dog", "wolf", "cat", "lynx", "tiger"] 
 
"6534-234-23-45".split "-" # => ["6534", "234", "23", "45"] 
 
calc = "45 + 36 - 25 * 14"
calc.split /\s*[-+*]\s*/ # => ["45", "36", "25", "14"]

Read the rest of this entry »

Extremely simple PubSubHubbub application with Ruby and Sinatra

February 10th, 2011

I’m starting to work on my project that is supposed to use PubSubHubbub. I had some difficulty understanding it as I found documentation inadequate. I have managed to get this simple app to work with a public Hub (http://pubsubhubbub.appspot.com/).

All it does is confirm all subscription requests, and when it recieves data it prints it on screen. It uses Sinatra for handling http requests. It’s not much but maybe someone will find it useful.

Read the rest of this entry »