Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7273

Re: extract into a method - struggling to abstract

X-Received by 10.31.65.147 with SMTP id o141mr30221616vka.6.1467637126887; Mon, 04 Jul 2016 05:58:46 -0700 (PDT)
X-Received by 10.157.27.242 with SMTP id v47mr1204996otv.16.1467637126844; Mon, 04 Jul 2016 05:58:46 -0700 (PDT)
Path csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!f89no2153131qtd.0!news-out.google.com!d62ni1553ith.0!nntp.google.com!jk6no10574937igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.ruby
Date Mon, 4 Jul 2016 05:58:46 -0700 (PDT)
In-Reply-To <dtsu6eFnso6U1@mid.individual.net>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=121.216.124.158; posting-account=5Cd8QAoAAAC6AxpkrISTgUBJ9ktgwNBm
NNTP-Posting-Host 121.216.124.158
References <df5ec7e9-0d75-4810-9f8c-5396113e8cc4@googlegroups.com> <dtsu6eFnso6U1@mid.individual.net>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <3e6ac674-4d74-45f5-a8e3-eb39ade446e1@googlegroups.com> (permalink)
Subject Re: extract into a method - struggling to abstract
From Sayth Renshaw <flebber.crue@gmail.com>
Injection-Date Mon, 04 Jul 2016 12:58:46 +0000
Content-Type text/plain; charset=UTF-8
X-Received-Bytes 2005
X-Received-Body-CRC 3790802056
Xref csiph.com comp.lang.ruby:7273

Show key headers only | View raw


for example template using json

noms.json

{
    "number": "nomination['number'].to_i",
    "id": "nomination['id'].to_i",
    "horse": "nomination['horse'].to_s",
    "age": "nomination['age'].to_i",
    "sex": "nomination['sex'].to_s",
    "colour": "/\W(.+?)\d?\s/.match(nomination['description'].to_s)[1]"
}

json.rb

require 'json'

file = File.read('noms.json')
data_hash = JSON.parse(file)
ary = 0..data_hash.length
ary.each do |x|
  out = "#{data_hash.keys[x]}: #{data_hash.values[x]}"
  puts out
end

_____________________________________________________________
out

number: nomination['number'].to_i
id: nomination['id'].to_i
horse: nomination['horse'].to_s
age: nomination['age'].to_i
sex: nomination['sex'].to_s
colour: /W(.+?)d?s/.match(nomination['description'].to_s)[1]

Is this a good idea to go down?

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

extract into a method - struggling to abstract Sayth Renshaw <flebber.crue@gmail.com> - 2016-07-03 07:01 -0700
  Re: extract into a method - struggling to abstract Robert Klemme <shortcutter@googlemail.com> - 2016-07-03 18:52 +0200
    Re: extract into a method - struggling to abstract Sayth Renshaw <flebber.crue@gmail.com> - 2016-07-04 05:58 -0700
    Re: extract into a method - struggling to abstract Sayth Renshaw <flebber.crue@gmail.com> - 2016-07-04 04:27 -0700
      Re: extract into a method - struggling to abstract Robert Klemme <shortcutter@googlemail.com> - 2016-07-05 23:21 +0200

csiph-web