@UnfalseIdeas

pascal Apr 17, 2013

What is the purpose of

Hash[one: 1, two: 1]

When you can write

{one: 1, two: 2}

Aren't you just passing a hash into the [] method?

increment_by_sql for PG

timdorr Apr 4, 2013

Note, if you're using the code below for incrementing by SQL with a Postgres database, it's not going to like the backticks. Just remove them:

def increment_with_sql!(attribute, by = 1)
raise ArgumentError("Invalid attribute: #{attribute}") unless attribute_names.include?(attribute.to_s)...

HTTPS request

a_aleksu Apr 4, 2013 1 thank

Hey, guys!

You have one mistake in example code.

uri = URI('https://secure.example.com/some_path?query=string')

Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https').start do |http|
request = Net::HTTP::Get.new uri.request_uri

response = http.request re...

Edge case

suzuki Mar 29, 2013

Have look how #between? handle adge case. It's different from DateTime's.

Date.yesterday.between?(Date.yesterday, Date.tomorrow)
=> true


Date.tomorrow.between?(Date.yesterday, Date.tomorrow)
=> true

Another Hash#without

Adkron Mar 13, 2013 1 thank

Mange made me think, and I wanted to expand on his example with a small change.

class Hash
def without(*keys)
  dup.without!(*keys)
end

def without!(*keys)
  reject! { |key| keys.include?(key) }
end
end

h = { :a => 1, :b => 2, :c => 3 }
h.without(:a)      #...