{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/6697","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6697/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6697/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6697/events","html_url":"https://github.com/crystal-lang/crystal/issues/6697","id":359043968,"node_id":"MDU6SXNzdWUzNTkwNDM5Njg=","number":6697,"title":"Allow inline instance method definition for a type","user":{"login":"vladfaust","id":7955682,"node_id":"MDQ6VXNlcjc5NTU2ODI=","avatar_url":"https://avatars2.githubusercontent.com/u/7955682?v=4","gravatar_id":"","url":"https://api.github.com/users/vladfaust","html_url":"https://github.com/vladfaust","followers_url":"https://api.github.com/users/vladfaust/followers","following_url":"https://api.github.com/users/vladfaust/following{/other_user}","gists_url":"https://api.github.com/users/vladfaust/gists{/gist_id}","starred_url":"https://api.github.com/users/vladfaust/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladfaust/subscriptions","organizations_url":"https://api.github.com/users/vladfaust/orgs","repos_url":"https://api.github.com/users/vladfaust/repos","events_url":"https://api.github.com/users/vladfaust/events{/privacy}","received_events_url":"https://api.github.com/users/vladfaust/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-09-11T13:18:38Z","updated_at":"2018-09-11T13:31:49Z","closed_at":"2018-09-11T13:26:49Z","author_association":"CONTRIBUTOR","body":"I'm sorry if it's a duplicate or already implemented.\r\n\r\n**Update:** `def Type.name` defines a method for a class, but what about instance methods?\r\n\r\nI'd like to see this possible:\r\n\r\n```crystal\r\ndef String.instance.foo\r\n  self + \", foo\"\r\nend\r\n\r\n\"bar\".foo\r\n# => \"bar, foo\"\r\n```\r\n\r\nMy usecase is defining `to_db` methods for an array of types in macros:\r\n\r\n```crystal\r\nclass URI\r\n  def to_db\r\n    to_s\r\n  end\r\nend\r\n\r\n{% for type in DB::TYPES %} # [Nil, String, Bool, Int32, Int64, Float32, Float64, Time, Bytes]\r\n  def {{type}}.instance.to_db\r\n    self\r\n  end\r\n{% end %}\r\n```\r\n\r\n`DB::TYPES` contain `String`, which is a class, and other types are structs. Without `def {{type}}.to_db`, I'd need to write separate def for `String` and for other methods. Also some types inherit, other don't. As a result, I'd have to write `to_db` for each type manually."},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/420275567","html_url":"https://github.com/crystal-lang/crystal/issues/6697#issuecomment-420275567","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6697","id":420275567,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDI3NTU2Nw==","user":{"login":"RX14","id":2788811,"node_id":"MDQ6VXNlcjI3ODg4MTE=","avatar_url":"https://avatars0.githubusercontent.com/u/2788811?v=4","gravatar_id":"","url":"https://api.github.com/users/RX14","html_url":"https://github.com/RX14","followers_url":"https://api.github.com/users/RX14/followers","following_url":"https://api.github.com/users/RX14/following{/other_user}","gists_url":"https://api.github.com/users/RX14/gists{/gist_id}","starred_url":"https://api.github.com/users/RX14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RX14/subscriptions","organizations_url":"https://api.github.com/users/RX14/orgs","repos_url":"https://api.github.com/users/RX14/repos","events_url":"https://api.github.com/users/RX14/events{/privacy}","received_events_url":"https://api.github.com/users/RX14/received_events","type":"User","site_admin":false},"created_at":"2018-09-11T13:31:49Z","updated_at":"2018-09-11T13:31:49Z","author_association":"MEMBER","body":"https://carc.in/#/r/4xws is far closer"}}
{"actor":{"display_login":"RX14"}}