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.