Saturday, August 22, 2020

Comments for Ruby Code (Usage, Single, and Multi-Line)

Remarks for Ruby Code (Usage, Single, and Multi-Line) Remarks in your Ruby code are notes and comments intended to be perused by different software engineers. The remarks themselves are overlooked by the Ruby mediator, so the content inside the remarks isnt subject to any limitations. Its normally great structure to put remarks before classes and strategies too any bit of code that might be perplexing or indistinct. Utilizing Comments Effectively Remarks ought to be utilized to give foundation data or clarify troublesome code. Notes that essentially state what the following line of clear code does are evident as well as add mess to the record. Its critical to take care not to utilize an excessive number of remarks and to be certain the remarks made in the record are important and accommodating to different software engineers. The Shebang Youll notice that every Ruby program start with a remark that starts with #!. This is known as a kit n kaboodle and is utilized on Linux, Unix and OS X frameworks. At the point when you execute a Ruby content, the shell, (for example, slam on Linux or OS X) will search for a kit n kaboodle at the primary line of the document. The shell will at that point utilize the thing to locate the Ruby mediator and run the content. The favored Ruby kit n kaboodle is #!/usr/receptacle/env ruby, however you may likewise observe #!/usr/container/ruby or #!/usr/nearby/canister/ruby. Single-Line Comments The Ruby single-line remark starts with the # character and finishes toward the stopping point. Any characters from the # character as far as possible of the line are totally overlooked by the Ruby mediator. The # character doesnt essentially need to happen toward the start ofâ the line; it can happen anyplace. The accompanying model outlines a couple of employments of remarks. #!/usr/receptacle/env ruby # This line is overlooked by the Ruby translator # This strategy prints the whole of its contentions def sum(a,b) Â â puts stomach muscle end sum(10,20) # Print the aggregate of 10 and 20 Multi-Line Comments In spite of the fact that regularly overlooked by numerous Ruby software engineers, Ruby has multi-line remarks. A multi-line remark starts with the start token and closures with the end token. These tokens should begin toward the start of the line and be the main thing on the line. Anything between these two tokens is overlooked by the Ruby translator. #!/usr/canister/env ruby start Between start and end, any number of lines might be composed. These lines are overlooked by the Ruby translator. end puts Hello world! In this model, the code would execute as Hello world!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.