Difference between DateTime and Time in Ruby

Ruby中的DateTime和Time类有什么区别,以及哪些因素会导致我选择其中一个? Newer versions of Ruby (2.0+) do not really have significant differences between the two classes. Some libraries will use one or the other for historical reasons, but new code does not necessarily need to be concerned. Picking one for consistency is probably best, so try and mesh with what your libraries expect. For exampl


Ruby中的DateTime和Time类有什么区别,以及哪些因素会导致我选择其中一个? 较新版本的Ruby(2.0+)在两个类之间并没有真正的显着差异。 由于历史原因,一些图书馆会使用其中一种,但新代码不一定需要担心。 为了一致性选择一个可能是最好的,所以尝试和你的图书馆期望的网格。 例如,ActiveRecord倾向于使用DateTime。 在Ruby 1.9之前的版本和许多系统上,Time被表示为一个32位有符号值,描述自UTC 1970年1月1日以来的秒

Ruby Email validation with regex

I have a large list of emails I am running through. A lot of the emails have typos. I am trying to build a string that will check valid emails. this is what I have for regex. def is_a_valid_email?(email) (email =~ /^(([A-Za-z0-9]*.+*_+)|([A-Za-z0-9]+-+)|([A-Za-z0-9]++)|([A-Za-z0-9]++))*[A-Z‌​a-z0-9]+@{1}((w+-+)|(w+.))*w{1,63}.[a-zA-Z]{2,4}$/i) end It passes if an email as underscores and


我有一大堆我正在运行的电子邮件。 很多电子邮件都有错别字。 我正在尝试构建一个字符串来检查有效的电子邮件。 这是我的正则表达式。 def is_a_valid_email?(email) (email =~ /^(([A-Za-z0-9]*.+*_+)|([A-Za-z0-9]+-+)|([A-Za-z0-9]++)|([A-Za-z0-9]++))*[A-Z‌​a-z0-9]+@{1}((w+-+)|(w+.))*w{1,63}.[a-zA-Z]{2,4}$/i) end 如果电子邮件为下划线且只有一个时段,则通过。 我有很多电子邮件的名称本身有多个时段。 我

Parsing text by regex, split, tokinize, or hash

I am parsing a CSV file that contains text that represents duration, which might be any combination of hours, minutes, or both. For example: "1 hour 30 minutes" "2 hours" "45 minutes" I want to be able to do this: duration = h.hours + m.minutes and make sure that h is hour (if exists) and the same for m . I tried solving this with this regex /(d*)s?hourD*(


我正在解析一个CSV文件,其中包含表示持续时间的文本,可能是小时,分钟或两者的任意组合。 例如: “1小时30分钟” “2小时” “45分钟” 我希望能够做到这一点: duration = h.hours + m.minutes并确保h是小时(如果存在)和m相同。 我尝试用这个正则表达式/(d*)s?hourD*(d*)s?min/)这个问题,但是这不会单独检测分钟,或者单独检测小时。 所以我把它改成了这个/(d+)s?D*s?(d*)/ ,但它也是错误的,因为没有办法确定这

Ruby email check (RFC 2822)

Does anyone know what the regular expression in Ruby is to verify an email address is in proper RFC 2822 email format? What I want to do is: string.match(RFC_2822_REGEX) where "RFC_2822_REGEX" is the regular expression to verify if my string is in valid RFC 2882 form. You can use the mail gem to parse any string according to RFC2822 like so: def valid_email( value ) begin re

Ruby电子邮件检查(RFC 2822)

有谁知道Ruby中的正则表达式是用来验证电子邮件地址是否采用正确的RFC 2822电子邮件格式? 我想要做的是: string.match(RFC_2822_REGEX) 其中“RFC_2822_REGEX”是正则表达式,用于验证我的字符串是否采用有效的RFC 2882格式。 您可以使用邮件gem根据RFC2822解析任何字符串,如下所示: def valid_email( value ) begin return false if value == '' parsed = Mail::Address.new( value ) return parsed.address

Ruby Regex to extract domain from email address

I have no real previous experience using regex, just saying. I want to extract domain names from email addresses with the below format. richardc@mydomain.com so that the regex returns just: mydomain With an explanation of how/why it works if possible! Cheers Here capturing (...) the domain name in group 1 and replace the whole string with that capture, which yields the domain name only at

Ruby Regex从电子邮件地址中提取域

我没有真正的使用正则表达式的经验,只是说。 我想用以下格式从电子邮件地址中提取域名。 richardc@mydomain.com,以便正则表达式只返回:mydomain 如果可能的话,解释它如何/为什么会起作用! 干杯 这里捕获(...)组1的域名,并用该捕获替换整个字符串,只在最后产生域名。 email = 'richardc@mydomain.com' domain = email.gsub(/.+@([^.]+).+/, '1') # => mydomain .+表示任何字符( n除外)。 所以它基本上匹配

Performance issues with Ruby and Net::SCP transfers (sockets)

SCP upload speeds seem to be limited greatly in the library from what the command line scp utility is capable of. I understand this is Ruby (1.9.2-p0), but Net::SCP is approximately 8x slower than the Linux utility (seen using large files... see below). I'm curious to know (I took a quick look at the code) if this is how sockets are in Ruby, or if it's possible to multiplex the Net::SCP

Ruby和Net :: SCP传输(套接字)的性能问题

SCP上传速度似乎受到命令行scp实用程序能够实现的极大限制。 我知道这是Ruby(1.9.2-p0),但Net :: SCP大约比Linux实用程序慢8倍(见大文件见......见下)。 我很想知道(我快速浏览了一下代码),如果这是在Ruby中的套接字,或者可以更好地复用Net :: SCP套接字? 我注意到,无论我尝试上传什么样的上传(串行上传,频道异步操作,使用多个scp对象实例),我永远无法在SCP上传中获得超过9兆字节/秒的传输速度。 现在.....

Sass/Compass compile into many locations

I'm using Sass 3.1.10 with Compass 0.11.5. I need to compile my compass project into many diffrent locations (css_dir) due some structural reasons. Currently I compile all files for each path by hand. Is there a way to compile into many locations at the same time? my config.rb looks like this: http_path = "/" css_dir = "skin/main/css" #css_dir = "uc/main/css" #css_dir = "skin/abstract/

Sass / Compass可以编译到很多地方

我在Compass 0.11.5上使用了Sass 3.1.10。 由于某些结构性原因,我需要将我的指南针项目编译到许多不同的位置(css_dir)。 目前我手工编译每个路径的所有文件。 有没有一种方法可以同时编译到多个位置? 我的config.rb看起来像这样: http_path = "/" css_dir = "skin/main/css" #css_dir = "uc/main/css" #css_dir = "skin/abstract/css" #css_dir = "skin/ksv/css" sass_dir = "sass" images_dir = "images" javascr

SASS/compass path in config.rb causing problem on compile

When I compile my SCSS, I'm getting a "file not found" error that leads me to believe there is something wrong with my config.rb. The error from the command line includes part of the path twice as well as the ".." relative directory: File not found or cannot be read: C:/REALLY_LONG_PATH/C:/REALLY_LONG_PATH/../img/avatar.jpg The config.rb reads as follows: # Delineate

config.rb中的SASS / compass路径导致编译时出现问题

当我编译我的SCSS时,我得到一个“文件未找到”的错误,导致我相信我的config.rb有问题。 命令行中的错误包括路径的两部分以及“..”相对目录: 文件未找到或无法读取:C:/ REALLY_LONG_PATH / C:/ REALLY_LONG_PATH /../ img / avatar.jpg config.rb的内容如下: # Delineate the directory for our SASS/SCSS files (this directory) sass_path = File.dirname(__FILE__) # Delineate the CSS directory (under resources/

Iterate over only public Ruby constants

Since Ruby 2.0 or so, it's been possible to make a constant private using private_constant , resulting in an error if the constant is used directly outside the declaring module. However, constants and const_defined? still return private constants, and const_get allows access to them. Is there a way to programmatically identify private constants and filter them out at run time? (Note: Wh


从Ruby 2.0开始,使用private_constant可以创建一个常量私有的,如果常量直接在声明模块外部使用,则会导致错误。 但是, constants和const_defined? 仍然返回私有常量, const_get允许访问它们。 有没有办法通过编程来识别私有常量并在运行时将其过滤掉? (注意:Module.private_constant是做什么的?有没有办法只列出私有常量?它的答案没有具体说明这种情况,而是相反的(如何仅列出私有常量)。 更新:看起来好像在

SecureRandom.uuid vs UUID gem

Is there a difference between ruby's SecureRandom.uuid (Ruby 1.9.3) and the UUID gem? Is the UUID gem the "old" way of doing things? From the docs I gather that the gem is more "safe" to be a real unique UUID while SecureRandom.uuid is more of a random string which has a larger chance of not being unique. In addition UUID seems to allow a file-based persistence to assi


ruby的SecureRandom.uuid(Ruby 1.9.3)和UUID gem有什么不同? UUID是否是“老”的做事方式? 从文档中我了解到,gem更“安全”是一个真正独特的UUID,而SecureRandom.uuid更像是一个随机字符串,它具有更大的不唯一性。 此外,UUID似乎允许基于文件的持久性来协助完成此操作。 所以我希望能听到一些比我更有见识的人。 有几种生成UUID的方法。 维基百科做了很好的列出。 http://en.wikipedia.org/wiki/Universally_uni