rubykeyword 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rubykeyword.rb +63 -0
  2. metadata +68 -0
@@ -0,0 +1,63 @@
1
+ class String
2
+
3
+ #Reference : http://ruby-doc.org/docs/keywords/1.9/
4
+ KEYWORDS = {
5
+ "BEGIN" => "Designates, via code block, code to be executed unconditionally before sequential execution of the program begins. Sometimes used to simulate forward references to methods.",
6
+ "END" => "Designates, via code block, code to be executed just prior to program termination.",
7
+ "__ENCODING__" => "The current default encoding, as an Encoding instance.",
8
+ "__END__" => "Denotes the end of the regular source code section of a program file. Lines below __END__ will not be executed. Those lines will be available via the special filehandle DATA. The following code will print out two stanzas of personal information. Note that __END__ has to be flush left, and has to be the only thing on its line.",
9
+ "__FILE__" => "The name of the file currently being executed, including path relative to the directory where the application was started up (or the current directory, if it has been changed). The current file is, in some cases, different from the startup file for the running application, which is available in the global variable",
10
+ "__LINE__" => "The line number, in the current source file, of the current line.",
11
+ "alias" => "Creates an alias or duplicate method name for a given method. The original method continues to be accessible via the alias, even if it is overriden. Takes two method-name arguments (which can be represented by strings or symbols but can also be the bare names themselves).",
12
+ "and" => "Boolean and operator. Differs from && in that and has lower precedence.",
13
+ "begin" => "Together with end, delimits what is commonly called a “begin” block (to distinguish it from the Proc type of code block). A “begin” block allows the use of while and until in modifier position with multi-line statements",
14
+ "break" => "Causes unconditional termination of a code block or while or until block, with control transfered to the line after the block. If given an argument, returns that argument as the value of the terminated block.",
15
+ "case" => "The case statement operator. Case statements consist of an optional condition, which is in the position of an argument to case, and zero or more when clauses. The first when clause to match the condition (or to evaluate to Boolean truth, if the condition is null) “wins”, and its code stanza is executed. The value of the case statement is the value of the successful when clause, or nil if there is no such clause.",
16
+ "class" => "Opens a class definition block. Takes either a constant name or an expression of the form << object. In the latter case, opens a definition block for the singleton class of object.",
17
+ "def" => "Paired with a terminating end, constitutes a method definition. Starts a new local scope; local variables in existence when the def block is entered are not in scope in the block, and local variables created in the block do not survive beyond the block.",
18
+ "defined?" => "defined? expression tests whether or not expression refers to anything recognizable (literal object, local variable that has been initialized, method name visible from the current scope, etc.). The return value is nil if the expression cannot be resolved. Otherwise, the return value provides information about the expression.",
19
+ "do" => "Paired with end, can delimit a code block",
20
+ "else" => "The else keyword denotes a final conditional branch. It appears in connection with if, unless, and case, and rescue. (In the case of rescue, the else branch is executed if no exception is raised.) The else clause is always the last branch in the entire statement, except in the case of rescue where it can be followed by an ensure clause.",
21
+ "elsif" => "Introduces a branch in a conditional (if or unless) statement. Such a statement can contain any number of elsif branches, including zero.",
22
+ "end" => "Marks the end of a while, until, begin, if, def, class, or other keyword-based, block-based construct.",
23
+ "ensure" => "Marks the final, optional clause of a begin/end block, generally in cases where the block also contains a rescue clause. The code in the ensure clause is guaranteed to be executed, whether control flows to the rescue block or not.",
24
+ "false" => "false denotes a special object, the sole instance of FalseClass. false and nil are the only objects that evaluate to Boolean falsehood in Ruby (informally, that cause an if condition to fail.)",
25
+ "for" => "A loop constructor, used with in:",
26
+ "if" => "Ruby’s basic conditional statement constructor. if evaluates its argument and branches on the result. Additional branches can be added to an if statement with else and elsif.",
27
+ "in" => "See for.",
28
+ "module" => "Opens a module definition block. Takes a constant (the name of the module) as its argument. The definition block starts a new local scope; existing variables are not visible inside the block, and local variables created in the block do not survive the end of the block.",
29
+ "next" => "Bumps an iterator, or a while or until block,to the next iteration, unconditionally and without executing whatever may remain of the block.",
30
+ "nil" => "A special “non-object”. nil is, in fact, an object (the sole instance of NilClass), but connotes absence and indeterminacy. nil and false are the only two objects in Ruby that have Boolean falsehood (informally, that cause an if condition to fail).",
31
+ "not" => "Boolean negation.",
32
+ "or" => "Boolean or. Differs from || in that or has lower precedence.",
33
+ "redo" => "Causes unconditional re-execution of a code block, with the same parameter bindings as the current execution.",
34
+ "rescue" => "Designates an exception-handling clause. Can occur either inside a begin<code>/<code>end block, inside a method definition (which implies begin), or in modifier position (at the end of a statement).",
35
+ "retry" => "Inside a rescue clause, retry causes Ruby to return to the top of the enclosing code (the begin keyword, or top of method or block) and try executing the code again.",
36
+ "return" => "Inside a method definition, executes the ensure clause, if present, and then returns control to the context of the method call. Takes an optional argument (defaulting to nil), which serves as the return value of the method. Multiple values in argument position will be returned in an array.",
37
+ "self" => "self is the current object and the default receiver of messages (method calls) for which no explicit receiver is specified. Which object plays the role of self depends on the context.",
38
+ "super" => "Called from a method, searches along the method lookup path (the classes and modules available to the current object) for the next method of the same name as the one being executed. Such method, if present, may be defined in the superclass of the object’s class, but may also be defined in the superclass’s superclass or any class on the upward path, as well as any module mixed in to any of those classes.",
39
+ "then" => "Optional component of conditional statements (if, unless, when). Never mandatory, but allows for one-line conditionals without semi-colons.",
40
+ "true" => "The sole instance of the special class TrueClass. true encapsulates Boolean truth; however, <emph>all</emph> objects in Ruby are true in the Boolean sense (informally, they cause an if test to succeed), with the exceptions of false and nil.",
41
+ "undef" => "Undefines a given method, for the class or module in which it’s called. If the method is defined higher up in the lookup path (such as by a superclass), it can still be called by instances classes higher up.",
42
+ "unless" => "The negative equivalent of if.",
43
+ "until" => "The inverse of while : executes code until a given condition is true, i.e., while it is not true. The semantics are the same as those of while; see while.",
44
+ "when" => "See case.",
45
+ "while" => "while takes a condition argument, and executes the code that follows (up to a matching end delimiter) while the condition is true.",
46
+ "yield" => "Called from inside a method body, yields control to the code block (if any) supplied as part of the method call. If no code block has been supplied, calling yield raises an exception.",
47
+ }
48
+
49
+ def keyword
50
+ return true if KEYWORDS.keys.include? self
51
+ return false
52
+ end
53
+
54
+ def define
55
+ if keyword
56
+ return KEYWORDS[self]
57
+ else
58
+ return false
59
+ end
60
+ end
61
+
62
+ end
63
+
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubykeyword
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Edwin Rozario
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-23 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Checks if a given string is a ruby keyword. Also defines the keyword
23
+ email:
24
+ - rozarioe@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - lib/rubykeyword.rb
33
+ has_rdoc: true
34
+ homepage: http://edwinrozario.posterous.com/
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: String Extend
67
+ test_files: []
68
+