In Ruby, although it's not a particularly common pattern, you can assign multiple variables on the left hand side of an assignment:
irb> a, b, c = [:hello, "world", 42]
irb> a
:hello
irb> b
"world"
irb> c
42
# See https://hexdocs.pm/elixir/List.html for reference | |
iex> list = [1, 2, 3] | |
iex> [list | 4] # fast, but probably not what you want | |
[[1, 2, 3] | 4] | |
iex> [0 | list] # fast | |
[0, 1, 2, 3] |
const a = { foo: 'foo'}; | |
const b = { bar: 'bar'}; | |
// the wrong way | |
const result = Object.assign(a, b); | |
console.log(a) | |
// { foo: 'foo', bar: 'bar' } | |
// this is usually bad, we usually don't want to mutate `a` in most cases | |
// The right ways: |
# these notes walk 2 excellent blogs posts: | |
# 1. http://awaxman11.github.io/blog/2013/08/05/what-is-the-difference-between-a-block/ | |
# 2. http://mixandgo.com/blog/mastering-ruby-blocks-in-less-than-5-minutes | |
arr = [1, 2, 3] | |
######################################################## | |
# example of a block | |
puts "block syntax demo" | |
arr.each do |element| |
!function(){function n(n){return n&&(n.ownerDocument||n.document||n).documentElement}function t(n){return n&&(n.ownerDocument&&n.ownerDocument.defaultView||n.document&&n||n.defaultView)}function e(n,t){return t>n?-1:n>t?1:n>=t?0:0/0}function r(n){return null===n?0/0:+n}function u(n){return!isNaN(n)}function i(n){return{left:function(t,e,r,u){for(arguments.length<3&&(r=0),arguments.length<4&&(u=t.length);u>r;){var i=r+u>>>1;n(t[i],e)<0?r=i+1:u=i}return r},right:function(t,e,r,u){for(arguments.length<3&&(r=0),arguments.length<4&&(u=t.length);u>r;){var i=r+u>>>1;n(t[i],e)>0?u=i:r=i+1}return r}}}function o(n){return n.length}function a(n){for(var t=1;n*t%1;)t*=10;return t}function c(n,t){for(var e in t)Object.defineProperty(n.prototype,e,{value:t[e],enumerable:!1})}function l(){this._=Object.create(null)}function s(n){return(n+="")===pa||n[0]===va?va+n:n}function f(n){return(n+="")[0]===va?n.slice(1):n}function h(n){return s(n)in this._}function g(n){return(n=s(n))in this._&&delete this._[n]}function p(){var n=[] |
!function(){function n(n){return n&&(n.ownerDocument||n.document||n).documentElement}function t(n){return n&&(n.ownerDocument&&n.ownerDocument.defaultView||n.document&&n||n.defaultView)}function e(n,t){return t>n?-1:n>t?1:n>=t?0:0/0}function r(n){return null===n?0/0:+n}function u(n){return!isNaN(n)}function i(n){return{left:function(t,e,r,u){for(arguments.length<3&&(r=0),arguments.length<4&&(u=t.length);u>r;){var i=r+u>>>1;n(t[i],e)<0?r=i+1:u=i}return r},right:function(t,e,r,u){for(arguments.length<3&&(r=0),arguments.length<4&&(u=t.length);u>r;){var i=r+u>>>1;n(t[i],e)>0?u=i:r=i+1}return r}}}function o(n){return n.length}function a(n){for(var t=1;n*t%1;)t*=10;return t}function c(n,t){for(var e in t)Object.defineProperty(n.prototype,e,{value:t[e],enumerable:!1})}function l(){this._=Object.create(null)}function s(n){return(n+="")===pa||n[0]===va?va+n:n}function f(n){return(n+="")[0]===va?n.slice(1):n}function h(n){return s(n)in this._}function g(n){return(n=s(n))in this._&&delete this._[n]}function p(){var n=[] |
{ | |
"nodes":[ | |
{ | |
"name": "Julie", | |
"gender": "female" | |
}, | |
{ | |
"name": "Matt", | |
"gender": "male" | |
}, |
#a simple solution to the "robots vs lasers" puzzle | |
#see http://www.puzzlenode.com/puzzles/4-robots-vs-lasers | |
#usage: | |
#simply run this program with ruby and pass the input file name as the sole argument | |
#example: ruby robots.rb sample-input.txt | |
######################################################### | |
#just use a structure since we only need to hold data |
#config/initializers/airbrake.rb | |
Airbrake.configure do |config| | |
config.api_key = 'mySecretKeyGoesHere' | |
config.ignore << "CustomSidekiqException" #do not report our custom exceptions to Airbrake | |
end |