Skip to content

Instantly share code, notes, and snippets.

@eltercero
Created July 17, 2015 13:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eltercero/20ad18c8d865549617bc to your computer and use it in GitHub Desktop.
Save eltercero/20ad18c8d865549617bc to your computer and use it in GitHub Desktop.
Snippet for creating a class with its attributes
<!--
Easily creates something like:
class Object
attr_reader :attr1, :attr2, :attr3
def initialize attr1, attr2, attr3
@attr1 = attr1
@attr2 = attr2
@attr3 = attr3
end
end
-->
<snippet>
<content><![CDATA[
class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}}
attr_reader ${2/(\w)+/:$MATCH/g}
def initialize $2
${2/(\w)+|,(\s)?/(?1@$MATCH = $MATCH)(?2\n\t\t)/g}
end
end
]]></content>
<tabTrigger>kla</tabTrigger>
<scope>source.ruby</scope>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment