- Lukasz Wrobel demystifies
nil
in Ruby
Why the id of nil is 4 in Ruby
- An older post by Neeraj Singh on
nil
'sobject_id
require 'open-uri' | |
require 'dotenv' | |
require 'json' | |
require 'pry' | |
Dotenv.load | |
# Basic structure of a Guardian API request: | |
# BASE_URI + endpoint + queries + api-key + params |
# Question source: http://codegolf.stackexchange.com/q/8574/12268 | |
# Write an algorithm in any programming language you desire | |
# that generates n unique randomly-distributed random natural | |
# numbers (i.e. positive integers, no zero), sum of which is | |
# equal to t, where t is bigger than or equal to n*(n+1)/2. | |
# Example: Generate 10 unique random natural numbers, sum of which is equal to 500. | |
def rand_sum(size, sum) |
fizzbuzz :: Int -> [String] | |
fizzbuzz n = take n $ addNums $ zipWith (++) fizz buzz | |
where fizz = cycle ["", "", "Fizz"] | |
buzz = cycle ["", "", "", "", "Buzz"] | |
addNums = zipWith numOrNot $ map show [1..] | |
numOrNot = \ x y -> if null y then x else y |
nil
in RubyWhy the id of nil is 4 in Ruby
nil
's object_id