aristotelesbr · @aristotelesbr
6 followers · 7 posts · Server ruby.social

A princípio, pode parecer estranho que um objeto não possa ser alterado após a sua criação, mas isso é algo que acontece com alguns tipos de objetos no Ruby, como por exemplo, Symbol e Integer.

Nesse post, abordo o conceito de imutabilidade no Ruby, discutindo como criar objetos imutáveis e explorando os benefícios dessa abordagem.

Você pode ver mais aqui 👇🏻

lnkd.in/epgydrnu

aristotelescoutinho.com.br/ent

#ruby #rubytips

Last updated 2 years ago

Nick · @nickcampbell
13 followers · 12 posts · Server ruby.social

I've been copying a variation of this snippet into most Ruby projects:

class BigDecimal
def inspect
"BigDecimal(\"#{to_s(?F)}\")"
end
end

It overrides the default appearance of a BigDecimal in an irb/pry/rails console. Why?

1. Easier to visually scan than exponential notation
2. Can be copy-pasted to get another bigdecimal (otherwise using exp notation yields a Float instance)

#ruby #rubytips

Last updated 3 years ago

Jim Nanney · @jnanney
49 followers · 49 posts · Server ruby.social

When you use the block syntax with Hash.new to define a default value, you lock yourself to only using the square bracket syntax for value lookup. The fetch method ignores the block, default, and default_proc.

This bit me hard this week, and my pair, @gd, got to watch me flounder on why fetch wasn’t getting the default value.

By the way, the Hash.new with a block is great for memorization of calculated or network lookup data.

#ruby #rubytips #rubygotchas #thisweekilearned #twil

Last updated 3 years ago

MoskitoHero :ruby: :emacs: · @MoskitoHero
136 followers · 2017 posts · Server mastodon.xyz

Nice. TL;DR: to measure elapsed time, don't use Time.now, use Process.clock_gettime(Process::CLOCK_MONOTONIC)

RT @piotr_murach@twitter.com

When measuring elapsed time in Ruby refrain from using Time.now call. Why? It is prone to "time drifting" and "errors in increase frequency" which may cause a negative time interval!😱

If you want to know more, read this 👉
blog.dnsimple.com/2018/03/elap by @jodosha@twitter.com

🐦🔗: twitter.com/piotr_murach/statu

#rubytips #ruby

Last updated 6 years ago