{"id":16688017,"url":"https://github.com/danielpclark/read_source","last_synced_at":"2025-04-10T00:33:48.781Z","repository":{"id":56891280,"uuid":"76756518","full_name":"danielpclark/read_source","owner":"danielpclark","description":"Read method source and even open it in VIM with this gem.","archived":false,"fork":false,"pushed_at":"2017-09-25T15:47:47.000Z","size":16,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-23T23:46:54.922Z","etag":null,"topics":["ruby","ruby-gem","source-parser","vim"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielpclark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-18T01:24:29.000Z","updated_at":"2018-03-09T13:41:14.000Z","dependencies_parsed_at":"2022-08-21T00:20:36.172Z","dependency_job_id":null,"html_url":"https://github.com/danielpclark/read_source","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2Fread_source","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2Fread_source/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2Fread_source/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2Fread_source/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielpclark","download_url":"https://codeload.github.com/danielpclark/read_source/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239088383,"owners_count":19579432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby","ruby-gem","source-parser","vim"],"created_at":"2024-10-12T15:26:28.026Z","updated_at":"2025-02-16T04:33:16.400Z","avatar_url":"https://github.com/danielpclark.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ReadSource\n[![Gem Version](https://badge.fury.io/rb/read_source.svg)](https://badge.fury.io/rb/read_source)\n[![Build Status](https://travis-ci.org/danielpclark/read_source.svg?branch=master)](https://travis-ci.org/danielpclark/read_source)\n[![SayThanks.io](https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg)](https://saythanks.io/to/danielpclark)\n\nHaha! This little gem was a distraction from my duties but I had to make it.\n\nAt first I was going to name it VIM-something because it lets you open the source code for a method in your VIM editor.\nBut as I thought about it I discovered it would be so simple to have Ruby read the method for itself. *Yes\nI know there is the `method_source` gem that has been around forever.* But if I'm writing a VIM method\nto read the source file I might as well throw in a method to string function.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'read_source'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install read_source\n\n## Usage\n\nThis gem adds instance methods to the Method and UnboundMethod objects.\n\n* `Method#vim`\n* `Method#attr?`\n* `Method#read_source`\n* `UnboundMethod#vim`\n* `UnboundMethod#attr?`\n* `UnboundMethod#read_source`\n\nCurrently this assumes VIM is in your executable path.  Future versions of this gem will be more\naccommodating to where VIM may be.\n\n```ruby\nrequire 'read_source'\n\nrequire 'pathname'\nputs Pathname.instance_method(:root?).read_source\n#def root?\n#  !!(chop_basename(@path) == nil \u0026\u0026 /#{SEPARATOR_PAT}/o =~ @path)\n#end\n\nPathname.instance_method(:root?).attr?\n# =\u003e nil\n\nrequire 'prime'\nputs Integer.method(:each_prime).read_source\n#def Integer.each_prime(ubound, \u0026block) # :yields: prime\n#  Prime.each(ubound, \u0026block)\n#end\n\nGem::BasicSpecification.instance_method(:base_dir=).attr?\n# =\u003e :attr_writer\n```\n\nYou can type `vim` instead of the `read_source` method on either the `Method` or `UnboundMethod` objects\nand it will close irb (or rails console) and open the source code file in VIM at the exact line where\nthe method is defined.\n\n--- \n\nIn case you didn't know Ruby already has a bunch of nice methods on `Method` and `UnboundMethod`\nthat are quite helpful.\n\n```ruby\nrequire 'read_source'\nrequire 'pathname'\n\nPathname.method(:autoload).owner\n# =\u003e Module \nPathname.method(:pwd).owner\n# =\u003e #\u003cClass:Pathname\u003e\nPathname.instance_method(:root?).source_location\n# =\u003e [\"/home/danielpclark/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/pathname.rb\", 208]\n```\n\n---\n\nNOTES:\n* If the source code is written in C then the `read_source` and `vim` methods only return nil.\n* If the file is in `GEM_HOME` path then VIM opens it in read only mode.\n\n## VIM\n\nWe now support VIM servers and can open code directly into your existing VIM session(s).  If you've started\na VIM server with the name of \"VIM\" then any time you call the `vim` method it will open in there **unless**\nyou choose to specify another servername as a parameter to `vim`.\n\n#### Start a VIM server with\n```ruby\n# A default server\nvim --servername VIM\n\n# An alternate server\nvim --servername SOMENAME\n```\n\nThen to open the code in VIM you would do:\n\n```ruby\n# If a server is named VIM (or else it will close current Ruby session and open vim in this terminal).\nGem::BasicSpecification.instance_method(:base_dir=).vim\n\n# Using a named server\nGem::BasicSpecification.instance_method(:base_dir=).vim 'SOMENAME'\n```\n\nThis way you can keep your ruby code running and open the code in an existing VIM instance.\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/danielpclark/read_source.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielpclark%2Fread_source","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielpclark%2Fread_source","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielpclark%2Fread_source/lists"}