view 1-Ruby/hashes.rb @ 93:39084e2b8744

Add a function for word-aware text wrapping Potentially hugely inefficient because we iterate through the string character by character, but then splitting it first and iterating over words still needs to iterate over the string to know where to split.
author IBBoard <dev@ibboard.co.uk>
date Tue, 18 Jun 2019 21:05:00 +0100
parents ebb19742b98f
children
line wrap: on
line source

#! /usr/bin/env ruby

# Ruby has inline hashmap definitions, like PHP.
# Java doesn't. C# isn't quite as clear as this "key => value" pattern.
frenchify = { 'one' => 'un', 'two' => 'deux' }
puts frenchify['one']

# Or, done properly with symbols:
frenchify = { :one => 'un', :two => 'deux' }
puts frenchify[:one]
# But what is a symbol? Its own class, apparently!
puts :one.class