Q:

How to access a custom field using Rally Ruby API

There is a custom field on Rally artifact that shows in WS API document as c_MyCustomField
but it does not print:
results = @rally.find(query)

results.each do |d|
       puts "Name: #{d["Name"]}, FormattedID: #{d["FormattedID"]}, Owner: #{d["Owner"]["UserName"]}, MyCustomField: #{d["c_MyCustomField"]}"
       d.read
end

A:

First, check that the field is being fetched:
query.fetch = "c_MyCustomField"

Next, a version of WS API has to be explicitly set if v2.0 is used.
c_ prefix is specific to WS API version v2.0.
By default rally_api is going to use a prior version of WS API.
If you do not explicitly specify WS API version in your code, refer to the custom field as it is refered to in the prior versions of WS API, without c_:
results.each do |d|
    puts "MyCustomField: #{d["MyCustomField"]}"
    d.read
end

If the latest version of WS API is set in the code:
config[:version] = "v2.0"

then the custom field should have c_ in front of it:
results.each do |d|
    puts "MyCustomField: #{d["c_MyCustomField"]}"
    d.read
end

This assumes that you are using RallyRestTookitForRuby with the latest rally_api gem. 
gem list -l

should list rally_api 0.9.20
Note that the older rally_rest_api is no longer supported. It will also not work with v2.0 of WS API.
Here is a ruby script example:
require 'rally_api'

#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "My Utility"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"

# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user@co.com"
config[:password] = "secret"
config[:workspace] = "W1"
config[:project] = "P1"
config[:version] = "v2.0"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()

@rally = RallyAPI::RallyRestJson.new(config)

query = RallyAPI::RallyQuery.new()
query.type = :defect
query.fetch = "c_MyCustomField"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/1111.js" } #optional
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222.js" } #Team Group 1 from Product 2
query.page_size = 200 #optional - default is 200
query.limit = 1000 #optional - default is 99999
query.project_scope_up = false
query.project_scope_down = true
query.order = "Name Asc"
query.query_string = "(Owner.UserName = someuser@co.com)"

results = @rally.find(query)

results.each do |d|
    puts "MyCustomField: #{d["c_MyCustomField"]}"
    d.read
end

