我正在尝试停止Amazon EC2实例并获得警告消息

警告:请注意,实例的临时存储上的任何数据在停止时都将丢失。

我的问题

哪些数据存储在Amazon EC2实例的临时存储中?

假设我有一个数组

[0, 132, 432, 342, 234]

去掉第一个元素最简单的方法是什么?(0)

使用Ruby,我如何在终端中为输出执行背景和前景文本着色?

我记得,在编程Pascal时,我们都习惯编写自己的textcolor(…)程序,以使我们的小教育程序看起来更漂亮、更有表现力。

我该如何在Ruby中编写类似的代码呢?核心库中是否有任何内置的支持来实现这一点?如果不是,什么是添加它的惯用方式?

在Ruby中读取文件的常见方法有哪些?

例如,这里有一个方法:

fileObj = File.new($fileName, "r")
while (line = fileObj.gets)
  puts(line)
end
fileObj.close

我知道Ruby非常灵活。每种方法的优点/缺点是什么?

我正在尝试理解块和yield以及它们在Ruby中的工作方式。

如何使用产量?我研究过的许多Rails应用程序都以一种奇怪的方式使用yield。

谁能给我解释一下或者告诉我怎么理解他们?

当我运行一个简单的Ruby脚本时,将对象的字段转储到控制台的最简单方法是什么?

我正在寻找与PHP的print_r()类似的东西,它也将与数组一起工作。

我正在尝试为Ruby安装PostgreSQL的pg gem。

我发出了以下命令:

gem install pg

我使用RVM安装Ruby 1.9.2。

上面的命令显示了以下错误。

错误是:

Building native extensions.  This could take a while...

ERROR:  Error installing pg:

ERROR: Failed to build gem native extension.

/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby extconf.rb

checking for pg_config... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
 --with-opt-dir
 --without-opt-dir
 --with-opt-include
 --without-opt-include=${opt-dir}/include
 --with-opt-lib
 --without-opt-lib=${opt-dir}/lib
 --with-make-prog
 --without-make-prog
 --srcdir=.
 --curdir
 --ruby=/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby
 --with-pg
 --without-pg
 --with-pg-config
 --without-pg-config
 --with-pg-dir
 --without-pg-dir
 --with-pg-include
 --without-pg-include=${pg-dir}/include
 --with-pg-lib
 --without-pg-lib=${pg-dir}/lib
 --enable-static-build
 --disable-static-build
 --with-pqlib
 --without-pqlib
 --with-libpqlib
 --without-libpqlib
 --with-ms/libpqlib
 --without-ms/libpqlib

Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0 for inspection.

Results logged to /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0/ext/gem_make.out

我不知道是什么错误…

我想运行这个查询:

SELECT DISTINCT ON (address_id) purchases.address_id, purchases.*
FROM purchases
WHERE purchases.product_id = 1
ORDER BY purchases.purchased_at DESC

但是我得到了这个错误:

SELECT DISTINCT ON表达式必须匹配表达式的初始顺序

添加address_id作为第一个ORDER BY表达式可以消除错误,但我真的不想在address_id上添加排序。有没有可能不按address_id排序?

刚安装El Capitan,不能安装gem eventmachine 1.0.7。Openssl的版本是1.0.2a-1。尝试使用——with-ssl-dir,但似乎被忽略了。

报告到他们的github回购以及。

任何建议都非常感谢。谢谢。

$ ls /usr/local/Cellar/openssl/1.0.2a-1/include/openssl/ssl.h
/usr/local/Cellar/openssl/1.0.2a-1/include/openssl/ssl.h

$ gem install eventmachine -v '1.0.7' -- --with-ssl-dir=/usr/local/Cellar/openssl/1.0.2a-1/include
/Users/pain/.rbenv/versions/2.1.2/bin/ruby -r ./siteconf20150612-56154-1hsjz2n.rb extconf.rb --with-ssl-dir=/usr/local/Cellar/openssl/1.0.2a-1/include
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_thread_fd_select()... yes
checking for rb_fdset_t in ruby/intern.h... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... no
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue... yes
checking for clock_gettime()... no
checking for gethrtime()... no
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling binder.cpp
In file included from binder.cpp:20:
./project.h:116:10: fatal error: 'openssl/ssl.h' file not found
#include <openssl/ssl.h>
         ^
1 error generated.
make: *** [binder.o] Error 1

make failed, exit code 2

我在Windows上运行Ruby,虽然我不知道这是否有什么不同。我所要做的就是获取当前工作目录的绝对路径。这可能从irb吗?显然,在脚本中可以使用File.expand_path(__FILE__)

但是从irb,我尝试了以下,得到了一个“权限被拒绝”错误:

File.new(Dir.new(".").path).expand