Well, this is a fun little puzzle from Google Blogoscoped
I’ve translated them to Ruby-esque code fragments (with some Rails-isms sprinkled in.)
original:
// idiom 1
cop [ 0 ]. goodInPercent = 100 ;
cop [ 1 ]. goodInPercent = 0 ;
my version:
GoodCop = cop [ 0 ]
BadCop = cop [ 1 ]
return GoodCop + BadCop
original:
// idiom 2
isCrowd = personCounter >= 3 ;
my version:
assert ( 3 == isCrowd )
original:
// idiom 3
injury += insult ;
my version:
return ( insult + injury )
// idiom 4
1 : board . draw ();
goto 1 ;
my version:
def Board . back
Board . type = 'drawing'
end
original:
// idiom 5
if ( bird [ 1 ]. feather == bird [ 2 ]. feather ) {
bird [ 1 ]. flock ( bird [ 2 ]);
}
my version:
flock . collect { | bird | feathers . each { | feather | bird . find_by_feather ( feather )}}
original:
// idiom 6
a = getThickness ( 'blood' );
b = getThickness ( 'water' );
assert ( a > b );
Blood . SpecificGravity = 1 . 0506 # reference: http://www.clinchem.org/cgi/content/abstract/20/5/615
Water . SpecificGravity = 1 . 0000
assert ( Blood . SpecificGravity > Water . SpecificGravity )
(See: [Specific Gravity of Blood and Plasma at 4 and 37°C][2])
[2]: http://www.clinchem.org/cgi/content/abstract/20/5/615 “Trudnowski and Rico · “Specific Gravity of Blood and Plasma at 4 and 37°C” · Clinical Chemistry 1974 20(5):615”
original:
// idiom 7
a_spade_a_spade ();
my version:
class Spade
def Spade . call ( value )
Spade . name = value
end
end
Spade . call ( 'Spade' )
original:
// idiom 8
die ( 1000 );
function die ( max ) {
for ( i = 1 ; i <= max ; i ++ ) {
cut ();
}
}
my version:
Death . find_by_cut ( '1000' )
original:
// idiom 9
prey = 'worm' ;
time = getCurrentTime ();
if ( time >= 4 && time <= 8 ) {
bird . catch ( prey );
}
my version:
bird = Creature . new ( :shift => 'early' )
worm = Creature . new
if bird . shift == 'early'
bird . catch ( worm )
end
original:
// idiom 10
while ( rome . fire () ) {
doFiddle ();
}
my version:
Nero ( :instrument => 'fiddle' ) while Rome . is_burning?
original:
// idiom 11
function getValue ( garbage ) {
return garbage ;
}
my version:
Value . In ( :Garbage )
print Value . Out
==> Garbage
original:
// idiom 12
take ( salt * . 01 );
my version:
Salt . take ( :mass => 0 . 0647 9891 , :unit => 'gram' )
original:
// idiom 13
var here = false ;
var there = false ;
my version:
assert ( ! ( here or there ) == true )
original:
// idiom 14
if ( i == 2 ) {
tango ();
}
my version:
def self . takes ( value )
if value == 2 then self . tango ();
end
</li>
original:
// idiom 15
days = 365 ;
for ( day = 1 ; day <= days ; day ++ ) {
if ( random ( 0 , 100 ) <= 50 ) apple ++ ;
}
if ( apple <= days ) doctor ();
my version:
year . collect { | day | if day . apple_count > 0 then doctor . keep_away ()}
original:
// idiom 16
if ( ! dogs . sleep () ) {
disturb ( dogs );
}
my version:
if dog . is_asleep? then dog . lay ()
original:
// idiom 17
function tunnel () {
var dark ;
for ( i = 0 ; i < 10 ; i ++ ) {
dark = true ;
}
dark = ! dark ;
return dark ;
}
my version:
Class Tunnel
def self . is_there_light?
return ( self . position == END )
end
end
original:
// idiom 18
if ( ape . inLineOfSight ( it . x , it . y ) ) ape . do ( it );
my version:
if monkey . does_see? ( :actor ) then monkey . do ( Monkey . action_seen ( :actor ))
original:
// idiom 19
return way . my || way . high ;
my version:
return way ( :my ) || way ( :high )
original:
// idiom 20
hay [ random ( 0 , hay . length - 1 ) ] = 'needle' ;
my version:
hay = Stack . new
hay . find ( 'needle' )
original:
// idiom 21
a = 0 ;
b = 1 ;
hand [ a ]. wash ( hand [ b ]);
hand [ b ]. wash ( hand [ a ]);
my version:
hand [ 'left' ]. wash ( hand [ 'right' ])
hand [ 'right' ]. wash ( hand [ 'left' ])
original:
// idiom 22
function getGain ( pain ) {
return pain >= 1 ;
}
my version:
if ( pain . level == 0 ) then gain . level = 0
original:
// idiom 23
if ( cooks >= 3 ) {
broth = null ;
}
my version:
if cook . count >= 3 then broth . is_spoiled? = true
original:
// idiom 24
if ( a != 'cake' ) a . eat ();
my version:
Class Cake
def Cake . have ()
Cake . is_had? = Cake . is_eaten? ? false : true
end
def Cake . eat ()
Cake . is_eaten? = Cake . is_had? ? false : true
end
end
original:
// idiom 25
doesStand = you == me ;
my version:
if We . is_united? then We . stand ()
if We . is_divided? then We . fall ()
original:
// idiom 26
var location = getLocation ();
if ( location == 'rome' ) {
do ( location . getCitizen () );
}
my version:
if person . locale == 'Rome' then person . behavior ( :Roman )
</ol>
initially published online on: Sun, February 24th, 2008 at 10:11 a.m. PST
page regenerated on: Thu, August 18th, 2016 at 9:41 a.m. PDT