You can use Ruby to view the function source code in the command line.

Source: Internet
Author: User

You can use Ruby to view the function source code in the command line.

To view the source code of the update_attribute function of ActiveRecord, a common method is to search for def update_attribute directly in the Rails source code. The Pragmatic Studio blog introduces a more convenient technique to enable direct access to The editor in The Ruby command line.

The Object of the update_attribute method can be obtained through the Object # Method method, while Method # source_location returns the file and location defined by this method. With this information, you can start the editor to view the source code:

Copy codeThe Code is as follows:
> Method = User. first. method (: update_attribute)
User Load (0.5 ms) SELECT 'users'. * FROM 'users' LIMIT 1
==## <Method: User (ActiveRecord: Persistence) # update_attribute>

> Location = method. source_location
=> ["/Users/wyx/. rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.2.11/lib/active_record/persistence. rb ",
177]

> 'Subl # {location [0] }:# {location [1]}'
=> ""

Encapsulate this code as a function and add it to. pryrc or. irbrc:
Copy codeThe Code is as follows:
Def source_for (object, method)
Location = object. method (method). source_location
'Subl # {location [0] }:# {location [1]} 'if location & location [0]! = '(Eval )'
Location
End

If you want to view the User's instance method update_attribute, you can directly call it in pry/irb
Copy codeThe Code is as follows:
Source_for (User. first,: update_attribute)

If you want to use another Editor, replace subl # {location [0] }:# {location [1]} with the command line corresponding to this editor:
Copy codeThe Code is as follows:
# TextMate
Mate # {location [0]}-l # {location [1]}

# MacVim
Mvim # {location [0]} + # {location [1]}

# Emacs
Emacs {location [0]} + # {location [1]}


Do I need to configure the environment after one-click ruby installation? I installed ruby on my computer and installed it with one click.

Follow these steps to check whether the ruby environment is configured:
1. Run -- cmd. Enter the command line mode.
2. Some ruby-v versions may be ruby -- version. View the ruby version currently installed.
3. irb
Puts 'test ruby Project'
Enter the above Code to test the code you want to test.
If the above problem occurs, it indicates that there is a problem with ruby installation or configuration.

The function of ParseCmdLine In the snort source code should be explained according to the source code.

I have parsed this Code. This is the address blog.csdn.net/fm5821/article/details/6376462.
However, my version is 2.6 and may be sorry for your source code.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.