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

Newsgroups comp.lang.ruby
Date 2016-07-04 05:58 -0700
References <df5ec7e9-0d75-4810-9f8c-5396113e8cc4@googlegroups.com> <dtsu6eFnso6U1@mid.individual.net>
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>

Show all headers | 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