如何为 rails 控制台创建自定义方法? [英] How to create a custom method for the rails console?

查看:41
本文介绍了如何为 rails 控制台创建自定义方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Ubuntu 中长时间使用 Rails 控制台时,我定义了 clear 方法:

When I'm using the Rails console in Ubuntu for a long session I define the clear method:

def clear;系统'清除'结束

所以当我的控制台变脏时,我唯一要做的就是输入 clear 并且控制台被清除.

So when my console is getting dirty the only thing I have to do is type clear and the console gets cleared.

我想使用这个功能而不必每次都重新输入.

I would like to use this function without to re-type it every time.

提前致谢.

推荐答案

只需将其放在 ~/.irbrc 文件中即可.每次运行 irbrails console 时都会加载它.Rails 控制台只是加载了 Rails 应用程序环境的 irb.

Just put it in the ~/.irbrc file. It gets loaded every time you run irb or rails console. The Rails console is just irb with your Rails application environment loaded.

在此处查找有关 irb 的更多信息:http://ruby-doc.com/docs/ProgrammingRuby/html/irb.html#S2

Find more infos about irb here: http://ruby-doc.com/docs/ProgrammingRuby/html/irb.html#S2

这篇关于如何为 rails 控制台创建自定义方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆