首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

ruby操作文件,该如何处理

2012-03-03 
ruby操作文件require app/configurationmodule RubyAMFmodule Configuration#set the service path used

ruby操作文件
require 'app/configuration'
module RubyAMF
  module Configuration
  #set the service path used in all requests
  # RubyAMF::App::RequestStore.service_path = File.expand_path(RAILS_ROOT) + '/app/controllers'

  # => CLASS MAPPING CONFIGURATION
  ClassMappings.register(
  :actionscript => 'Stock',
  :ruby => 'Stock',
  :type => 'active_record',
  :attributes => ["code", "name"])
  end
end
ClassMappings.register(
  :actionscript => 'Rolestock',
  :ruby => 'Rolestock',
  :type => 'active_record',
  :associations => ["stock"],
  :attributes => ["id", "cost", "amount"])



上面算是整个文件吧,之后我在另一个同等级路径文件下要操作这个文件


  File.open("rubyamf_config.rb") do |file|
  while line = file.gets
  unless line.include?("#")
  line.scan(//)
  print line
  end
  end
  file.close
  end

怎么操作呢,1.把注释的不显示,之后把下面的代码写到一个数组里,如最下面的模式
ClassMappings.register(
  :actionscript => 'Stock',
  :ruby => 'Stock',
  :type => 'active_record',
  :attributes => ["code", "name"])

模式:
{'ClassMappings.register' => ['actionscript' => 'Stock', 'ruby' => 'Stock', 'type' => 'active_record', 'attributes' => ["code", "name"]]}


ruby操作这些玩意还真不会呢!哎!如能回答,另加一百分

[解决办法]
学习了~~ 高手!!

热点排行