Symbol-Schlüssel in Ruby
Level 4130 Tastenanschläge
Erstellt einen Hash in der Schreibweise key: value mit Symbolen als Schlüsseln, gibt alle Paare aus und liest einen Wert mit config[:port].
Ruby-Code
# host: ist die Kurzform von :host => "localhost", die Schlüssel sind also Symbole1config = {2 host: "localhost",3 port: 3000,4 debug: true5}# Durchläuft jedes Schlüssel-Wert-Paar in Einfügereihenfolge6config.each do |key, value| # Das Symbol erscheint ohne Doppelpunkt: host: localhost7 puts "#{key}: #{value}"8end# Zugriff per Symbol; gibt 3000 aus9puts config[:port]Ausgabe
host: localhost port: 3000 debug: true 3000
Übe, diesen Code zu tippen. Ergebnisse werden nicht in der Rangliste gespeichert.
Symbole in diesem Code
Die Symbole, die du in diesem Ruby-Code tippst, und wie oft sie vorkommen.
:× 5"× 4,× 3{× 3}× 3#× 2|× 2.× 1[× 1]× 1