Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1073585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:00:38+00:00 2026-05-16T21:00:38+00:00

I find myself often writing statements equivalent to: deleted_at = Time.at(data[:deleted_at]) if !data[:deleted_at].nil? i’d

  • 0

I find myself often writing statements equivalent to:

deleted_at = Time.at(data[:deleted_at]) if !data[:deleted_at].nil?

i’d like to be able to write this in a more concise way. Any suggestions?

Sometimes I write this as:

deleted_at = Time.at(i) if !(i = data[:deleted_at]).nil?

But I think this makes the code harder to read so I hope there is some nicer way to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:00:39+00:00Added an answer on May 16, 2026 at 9:00 pm

    I use ‘unless’ since I find it more readable:

    deleted_at = Time.at(data[:deleted_at]) unless data[:deleted_at].nil?
    

    or you could even use:

    deleted_at = Time.at(data[:deleted_at]) if data[:deleted_at]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Often I find myself writing code like this: if (Session != null) { Session.KillAllProcesses();
Using ValueInjecter, I often find myself writing code like this: var foo1 = new
In my day-to-day work, I often find myself writing classes like in this simplified
Quite often I find myself writing code like this: Dim oRenewalOrder = (From c
I often find myself writing class constructors like this: class foo: def __init__(self, arg1,
I find myself writing stuff like this too often and it seems too wordy:
While striving for const-correctness, I often find myself writing code such as this class
I find myself creating Converters often and would like to be able to: right-click
I often find myself writing this: params.delete(:controller) params.delete(:action) params.delete(:other_key) redirect_to my_path(params) The trail of
When I'm writing shell scripts, I often find myself spending most of my time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.