DISQUS

DISQUS Hello!  The comments on this profile are unclaimed and thus are unverified.

Do they belong to you? Claim these comments.

Farrel Lifson's picture

Unregistered

Feeds

aliases

  • Farrel Lifson

Farrel Lifson

3 years ago

in Random Ruby Password Magic on Life is grand
IMO I prefer 8.times over 1.upto(8).

3 years ago

in A dirty Ruby on Life is grand
I did some further experimenting and it seems it's recommended to use Array(object) instead of object.to_a.

3 years ago

in A dirty Ruby on Life is grand
Also if you really want to squeeze things down you can do this:

@tag = Tag.find_by_syn_id(tag.id) || Tag.new
@tag.name = tag.name
@tag.sync_id ||= tag.id
@tag.save

3 years ago

in A dirty Ruby on Life is grand
I haven't used WSDLDriver but doe the tag object respond to to_a? If so you can do the following:

if soapResponse.getNewTagsSinceResult.respond_to? "tag"
for tag in soapResponse.getNewTagsSinceResult.tag.to_a
@tag = Tag.find_by_sync_id(tag.id)
if (@tag)
@tag.name = tag.name
@tag.save
else
@tag = Tag.new
@tag.name = tag.name
@tag.sync_id = tag.id
@tag.save
end
end
end

Just a quick warning that currently all objects respond to to_a but this will soon be deprecated so for future versions it's better to check that the tag object class explicity implements to_a.

3 years ago

in Commenting in Ruby on Life is grand
Pretty much most people don't even use the =begin/=end blocks any more. I just write stuff like

# This function adds two numbers together.
# No overflow checking is provided.
def sum(a,b)
a + b
end

It's easier to read and makes the comments more discernible.
Returning? Login