Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

ak

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Ruby Format Strings

// http://www.rubywiki.de/wiki/Tricks

'<p id="%d" class="%s">%s</p>' % [
  @node.id,
  @node.class,
  @node.value,
]

String replace trick

// InPlace Array.each
// http://www.rubywiki.de/wiki/Tricks
// Deletes the first two chars

a = [ "xxEins", "xxZwei", "xxDrei" ]

a.each do |s|
  s.replace( s[2..-1] )
end

p a  # >> ["Eins", "Zwei", "Drei"] 

Functions, that returns more

// Self explaining.

function return_more() {
	return array('first', 'second');
}

list($ret1, $ret2) = return_more();

echo $ret1.'<br>';
echo $ret2.'<br>';
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS