How to make

I don't use the RI or RDoc output from the gems I install in my machine or in the servers I handle (I use other means of documentation). Every gem I install installs RI and RDoc documentation by default, because I forget to set --no-ri --no-rdoc . Is there a way to make those two flags the default? You just add following line to your local ~/.gemrc file (it is in your home folder) gem:

怎么做

我不使用从我的机器或我处理的服务器(我使用其他文档方式)安装的gem中的RI或RDoc输出。 我安装的每个gem都会默认安装RI和RDoc文档,因为我忘记设置--no-ri --no-rdoc 。 有没有办法让这两个标志为默认值? 您只需~/.gemrc添加到您的本地~/.gemrc文件(它位于您的主文件夹中) gem: --no-document 或者您可以将此行添加到全局gemrc配置文件中。 这里是如何找到它(在Linux中) strace gem source 2>&1 | grep g

ruby koala facebook graph geting public events

I want to get a list of events from a venues facebook page. There is code to configure koala at https://github.com/arsduo/koala. I setup a facebook App in Facebook and have app_id and app_secret but after much googleing cant work out where to get 'access_token = MY_TOKEN' or 'app_access_token = MY_APP_ACCESS_TOKEN'. Ive looked at the Graph API Explorer (https://developers.face

红宝石考拉facebook graph geting公共活动

我想从场地的脸书页面得到一个事件列表。 有代码可以在https://github.com/arsduo/koala上配置考拉。 我在Facebook上设置了一个Facebook应用程序,并且有app_id和app_secret,但是很多googleing无法找到'access_token = MY_TOKEN'或'app_access_token = MY_APP_ACCESS_TOKEN'的位置。 我查看了Graph API Explorer(https://developers.facebook.com/tools/explorer),但似乎无法解决如何做到这一点。 例如

How to run Sinatra App in Passenger with Nginx?

I'm trying to run a very simple Sinatra app using my existing Nginx & Passenger setup. I'm familiar with running Rails on Passenger but this is my first time setting up Sinatra. I've installed Sinatra through bundler and RVM. Take a look at my configuration and tell me what I'm doing wrong. Nginx conf: server { listen 80; server_name demo.my-example.com; ro

如何使用Nginx在乘客中运行Sinatra应用程序?

我正在尝试使用我现有的Nginx&Passenger设置来运行一个非常简单的Sinatra应用程序。 我熟悉在乘客上运行Rails,但这是我第一次创建Sinatra。 我已经通过捆绑器和RVM安装了Sinatra。 看看我的配置,并告诉我我做错了什么。 Nginx conf: server { listen 80; server_name demo.my-example.com; root /home/user/demo.my-example.com/sinatra; passenger_ruby /usr/local/rvm/wrappers/ruby-2.3.1@my_

How to pass command line arguments to a rake task

I have a rake task that needs to insert a value into multiple databases. I'd like to pass this value into the rake task from the command line, or from another rake task. How can I do this? options and dependencies need to be inside arrays: namespace :thing do desc "it does a thing" task :work, [:option, :foo, :bar] => [:environment] do |t, args| puts "work", args end ta

如何将命令行参数传递给rake任务

我有一个需要将值插入多个数据库的rake任务。 我想通过命令行或其他rake任务将此值传递给rake任务。 我怎样才能做到这一点? 选项和依赖关系需要在数组内部: namespace :thing do desc "it does a thing" task :work, [:option, :foo, :bar] => [:environment] do |t, args| puts "work", args end task :another, [:option, :foo, :bar] => [:environment] do |t, args| puts "another #{args}"

Why "else"?

I'm trying to understand exceptions in Ruby but I'm a little confused. The tutorial I'm using says that if an exception occurs that does not match any of the exceptions identified by the rescue statements, you can use an "else" to catch it: begin # - rescue OneTypeOfException # - rescue AnotherTypeOfException # - else # Other exceptions ensure # Always will b

为什么“其他”?

我想了解Ruby中的异常,但我有点困惑。 我正在使用的教程说,如果发生的异常与救援语句标识的任何异常不匹配,您可以使用“else”来捕获它: begin # - rescue OneTypeOfException # - rescue AnotherTypeOfException # - else # Other exceptions ensure # Always will be executed end 但是,我也在后面的教程中看到“rescue”正在使用,没有指定例外情况: begin file = open("/unexistant_file") if fi

Blocks and yields in Ruby

I am trying to understand blocks and yield and how they work in Ruby. How is yield used? Many of the Rails applications I've looked at use yield in a weird way. Can someone explain to me or show me where to go to understand them? Yes, it is a bit puzzling at first. In Ruby, methods may receive a code block in order to perform arbitrary segments of code. When a method expects a bloc

Ruby中的块和产量

我试图理解块和yield ,以及它们如何在Ruby中工作。 如何使用yield ? 我看过的许多Rails应用程序都以一种奇怪的方式使用yield 。 有人可以向我解释或告诉我去哪里了解他们吗? 是的,起初有点令人费解。 在Ruby中,方法可以接收代码块以执行任意代码段。 当一个方法需要一个块时,它通过调用yield函数来调用它。 例如,这非常方便,可以遍历列表或提供自定义算法。 以下面的例子: 我将定义一个用名称初始化的

Get the value of an instance variable given its name

In general, how can I get a reference to an object whose name I have in a string? More specifically, I have a list of the parameter names (the member variables - built dynamically so I can't refer to them directly). Each parameter is an object that also has an from_s method. I want to do something like the following (which of course doesn't work...): define_method(:from_s) do | arg

根据名称获取实例变量的值

一般来说,我怎样才能得到一个字符串中对象名称的引用? 更具体地说,我有一个参数名称列表(成员变量 - 动态构建,所以我不能直接引用它们)。 每个参数都是一个也具有from_s方法的对象。 我想做类似下面的事情(这当然不起作用......): define_method(:from_s) do | arg | @ordered_parameter_names.each do | param | instance_eval "field_ref = @#{param}" field_ref.from_s(param) end en

Why use Ruby's attr

Ruby has this handy and convenient way to share instance variables by using keys like attr_accessor :var attr_reader :var attr_writer :var Why would I choose attr_reader or attr_writer if I could simply use attr_accessor ? Is there something like performance (which I doubt)? I guess there is a reason, otherwise they wouldn't have made such keys. You may use the different accessors to co

为什么要使用Ruby的属性

Ruby有这种方便和方便的方式来通过使用键等方式共享实例变量 attr_accessor :var attr_reader :var attr_writer :var 为什么我会选择attr_reader或attr_writer如果我可以简单地使用attr_accessor ? 有没有像表现(我怀疑)? 我猜这是有原因的,否则他们不会做出这样的关键。 您可以使用不同的访问器将您的意图传达给阅读您的代码的人,并且使得编写无论公用API如何调用都能正常工作的类更容易。 class Person attr_acc

Line Comments in Ruby?

我如何评论Ruby中的多行? #!/usr/bin/env ruby =begin Every body mentioned this way to have multiline comments. The =begin and =end must be at the beginning of the line or it will be a syntax error. =end puts "Hello world!" <<-DOC Also, you could create a docstring. which... DOC puts "Hello world!" "..is kinda ugly and creates a String instance, but I know one guy with a Smalltalk backgr

Ruby中的行注释?

我如何评论Ruby中的多行? #!/usr/bin/env ruby =begin Every body mentioned this way to have multiline comments. The =begin and =end must be at the beginning of the line or it will be a syntax error. =end puts "Hello world!" <<-DOC Also, you could create a docstring. which... DOC puts "Hello world!" "..is kinda ugly and creates a String instance, but I know one guy with a Smalltalk backgr

How to write to file in Ruby?

I need to read the data out of database and then save it in a text file. How can I do that in Ruby? Is there any file management system in Ruby? Ruby File类将为您提供::new和::open来龙去脉,但它的父类IO类深入到#read和#write 。 你在寻找以下吗? File.open(yourfile, 'w') { |file| file.write("your text") } You can use the short version: File.write('/path/to/file', 'Some glorious content') It r

如何在Ruby中写入文件?

我需要从数据库中读取数据,然后将其保存在文本文件中。 我如何在Ruby中做到这一点? Ruby中是否有任何文件管理系统? Ruby File类将为您提供::new和::open来龙去脉,但它的父类IO类深入到#read和#write 。 你在寻找以下吗? File.open(yourfile, 'w') { |file| file.write("your text") } 您可以使用简短版本: File.write('/path/to/file', 'Some glorious content') 它返回写入的长度; 看到::写更多的细节和选项。