Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 334 Bytes

fetch-data.md

File metadata and controls

23 lines (15 loc) · 334 Bytes

Fetch data

params = {var: 42}

p params.fetch(:var)
p params.fetch(:missing, 42)
p params.fetch(:missing) { 40 + 2 }

params.fetch(:missing)


# Result:
# 42
# 42
# 42
# ./fetch_data.rb:7:in `fetch': key not found: :missing (KeyError)
# 	from ./fetch_data.rb:7:in `<main>'

View Source