Actually the following code does not work
var = 'a' alpha = {:var => 1} alpha[var] => 1
Same with
var = 'a' alpha = {var: 1} alpha[:var] => 1
They actually create a symbol key :var instead of a string key a
:var
a
alpha.keys => [:var]
If you want to use the value from a variable(in this case var), then you should do it like this
var
var = 'a' alpha = { var => 1 } alpha[var] => 1
This code also does not work
fav_dogs.each {|dog, number| if dog == :not_dogs puts number }
It seems you forgot an end somewhere(twice). Also as a side note {} blocks can be replaced with do...end blocks.
end
{}
do...end
Something like this
fav_dogs.each do |dog, number| if dog == :not_dogs puts number end end fav_dogs.each { |dog, number| if dog == :not_dogs puts number end }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Actually the following code does not work
Same with
They actually create a symbol key
:var
instead of a string keya
If you want to use the value from a variable(in this case
var
), then you should do it like thisThis code also does not work
It seems you forgot an
end
somewhere(twice). Also as a side note{}
blocks can be replaced withdo...end
blocks.Something like this