grep char后跟包含特定其他字符的任何内容(grep char followed by anything containing specific other characters)
我想使用grep在目录(/ bin)中搜索以特定字符开头的任何内容,然后是包含两个其他特定字符之一的任何字符串。 在我的情况下,我希望每个文件以'g'开头并包含字母'e'或'n'。 我尝试了很多“ls / bin | grep'^ g'”的变体。
I would like to use grep to search a directory (/bin) for anything starting with a specific character and followed by any string containing one of two other specific characters. In my case I want every file starting with a 'g' and contain the letters 'e' or 'n'. I have tried many variations of "ls /bin | grep '^g'".
原文:https://stackoverflow.com/questions/43374346
最满意答案
要覆盖原始Model方法,可以编写具有相同名称的方法,然后使用
read_attribute(:attr)
表示原始属性值。给定
name
属性,覆盖#name
:def name "#{salutation} #{read_attribute(:name)}" end
To overwrite an original Model method, you can write a method with same name, and then use
read_attribute(:attr)
to represent the original attribute value.Given
name
attribute exist, to overwrite#name
:def name "#{salutation} #{read_attribute(:name)}" end
相关问答
更多-
@语法用于(例如)在控制器中填充的实例变量,然后在视图中使用。 不是你在这里做什么。 你其实只是需要 def formal_name title + " " + forename + " " + surname end The @ syntax is used for instance variables that (for example) get populated in controllers and then used in views. Not what you're doing here. ...
-
@options在类级别不存在。 Ruby首先评估序列化程序类和方法定义。 然后创建一个选项哈希值,在渲染时将其传递给序列化程序类的新实例。 访问这些选项的方法实际上是在ActiveModel :: Serializer的更高版本中命名为instance_options 。 但是,你仍然可以完成你想要的。 最简单的方法是在渲染时使用except:选项。 除了传递include_notes: false您可以在不需要关联时传递except: [:notes] 。 @options doesn't exist ...
-
不幸的是,看起来你必须更长时间地为你的评论设置保存回调。 我浏览了宝石,看起来好像没有通过一个稍后调用的proc来支持(见这里 )。 顺便说一下 : 除了调用类方法而不是实例方法这一事实外, self.comments.count在加载类时评估self.comments.count ,当您调用时, self.comments.count对其进行评估: value :redis_comment_count, :default => self.comments.count # This becomes: ...
-
您可以直接创建与Oracle的连接,然后让ActiveRecord执行原始SQL语句来查询您的表(复数)。 在我头顶上,像这样: class OracleModel < ActiveRecord::Base establish_connection(:oracle_development) def self.get_objects self.find_by_sql("SELECT...") end end 使用此模型,您可以执行OracleModel.get_objects ,它将返 ...
-
用2.2你不能。 但是3.0可能会有这样的功能。 观看我们的博客了解新闻。 With 2.2 you can't. However 3.0 will probably have such a feature. Watch our blog for news.
-
问题是在内核中已经有一个名为“display”的方法与ActiveRecord的魔法相冲突。 ActiveRecord定义method_missing中与数据库字段对应的方法。 因此,在调用method_missing之前,这些方法实际上并不存在。 当你在@thing上调用name时,会调用method_missing,因为没有name方法。 但是,当您调用display(之前没有调用另一个不存在的方法)时,不会调用method_missing,因为已在Kernel中定义了display并且执行了此定义。 ...
-
一些评论: 您不必(实际上不能)始终使用self接收器调用方法。 例如,私有方法只能在没有显式接收器的情况下调用,因此不能self.调用self. 私人方法...... 你为什么不检查网址并检查它是否正确? 只需在您分配puts url的行之后添加puts url ,运行程序并检查输出。 网址是否正确? 您可能没有正确使用HTTParty: HTTParty.get('...')返回一个响应对象,您可能必须正确解析响应的正文。 JSON服务的示例: url = 'http://service.co ...
-
这类似于人们在使用AngularJS调用JQuery $.ajax遇到的其他问题 如果你看一下Angular的这个概述,你会看到Angular将所有内容编译到它自己的执行上下文中。 您需要将Rails调用置于角度,以便数据显示在$scope 解决此问题的两个选项是: 切换到AngularJS $http服务。 这将是我的偏好:一切都已经在Angular中,你可以删除你在另一个库上的dependendy 。 在$scope.$apply方法中包含你的调用,以在Rails调用完成时触发$digest循环 Thi ...
-
在Rails中访问时使用Instance方法而不是Database字段(Use Instance method instead of Database field while accessing in Rails)[2021-12-03]
要覆盖原始Model方法,可以编写具有相同名称的方法,然后使用read_attribute(:attr)表示原始属性值。 给定name属性,覆盖#name : def name "#{salutation} #{read_attribute(:name)}" end To overwrite an original Model method, you can write a method with same name, and then use read_attribute(:attr) to rep ... -
使用attr_reader读取实例变量的值 class Person attr_reader :name def initialize(name) @name = name end end john = Person.new("John") john.name #=> "John" 在这种情况下, attr_reader为类添加了一个getter方法 def name @name end 希望有所帮助! Use attr_reader to read the value of ...