{"id":22739,"date":"2023-02-28T07:07:34","date_gmt":"2023-02-28T07:07:34","guid":{"rendered":"https:\/\/www.booksofall.com\/cn\/?post_type=product&#038;p=22739"},"modified":"2023-02-28T07:07:35","modified_gmt":"2023-02-28T07:07:35","slug":"using-blocks-in-ruby","status":"publish","type":"product","link":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/","title":{"rendered":"Using Blocks in Ruby"},"content":{"rendered":"<p>A <a href=\"https:\/\/en.wikipedia.org\/wiki\/Block_programming\">block<\/a> is a chunk of code that you associate with a method call. While the method runs, it can invoke (execute) the block one or more times. Methods and blocks work in tandem to process your data. Blocks are a way of encapsulating or packaging statements up and using them wherever you need them. They turn up all over <a href=\"https:\/\/acloudguru.com\/blog\/engineering\/what-is-the-ruby-programming-language#:~:text=What%20is%20Ruby%3F,interpreter%20and%20turned%20into%20code.\">Ruby code<\/a>.<\/p>\n<p>Blocks are mind-bending stuff. But stick with it!<\/p>\n<p>Even if you\u2019ve programmed in other languages, you\u2019ve probably never seen anything like blocks. But stick with it, because the payoff is big.<\/p>\n<p>Imagine if, for all the methods you have to write for the rest of your career, someone else wrote half of the code for you. For free. They\u2019d write all the tedious stuff at the beginning and end, and just leave a little blank space in the middle for you to insert your code, the clever code, the code that runs your business.<\/p>\n<p>If we told you that blocks can give you that, you\u2019d be willing to do whatever it takes to learn them, right?<\/p>\n<p>Well, here\u2019s what you\u2019ll have to do: be patient, and persistent. We\u2019re here to help. We\u2019ll look at each concept repeatedly, from different angles. We\u2019ll provide exercises for practice. Make sure to do them, because they\u2019ll help you understand and remember how blocks work.<\/p>\n<p>A few hours of hard work now are going to pay dividends for the rest of your Ruby career, we promise. Let\u2019s get to it!<\/p>\n<p>Ruby\u00a0is an\u00a0<a class=\"mw-redirect\" title=\"Interpreted language\" href=\"https:\/\/en.wikipedia.org\/wiki\/Interpreted_language\">interpreted<\/a>,\u00a0<a title=\"High-level programming language\" href=\"https:\/\/en.wikipedia.org\/wiki\/High-level_programming_language\">high-level<\/a>,\u00a0<a title=\"General-purpose programming language\" href=\"https:\/\/en.wikipedia.org\/wiki\/General-purpose_programming_language\">general-purpose programming language<\/a> that supports multiple\u00a0<a title=\"Programming paradigm\" href=\"https:\/\/en.wikipedia.org\/wiki\/Programming_paradigm\">programming paradigms<\/a>. It was designed with an emphasis on programming productivity and simplicity. In Ruby, everything is an object, including\u00a0<a title=\"Primitive data type\" href=\"https:\/\/en.wikipedia.org\/wiki\/Primitive_data_type\">primitive data types<\/a>. It was developed in the mid-1990s by\u00a0<a title=\"Yukihiro Matsumoto\" href=\"https:\/\/en.wikipedia.org\/wiki\/Yukihiro_Matsumoto\">Yukihiro &#8220;Matz&#8221; Matsumoto<\/a>\u00a0in\u00a0<a title=\"Japan\" href=\"https:\/\/en.wikipedia.org\/wiki\/Japan\">Japan<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><iframe style=\"width: 100%; height: 700px; border: none;\" src=\"https:\/\/online.visual-paradigm.com\/share\/book\/using-blocks-in-ruby-19tu49ifyw?enforceShowPromotionBar=true&amp;p=1\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"featured_media":22743,"template":"","meta":{"_yoast_wpseo_title":"","_yoast_wpseo_metadesc":""},"product_brand":[],"product_cat":[371],"product_tag":[],"class_list":{"0":"post-22739","1":"product","2":"type-product","3":"status-publish","4":"has-post-thumbnail","6":"product_cat-ruby","8":"first","9":"instock","10":"shipping-taxable","11":"product-type-simple"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using Blocks in Ruby - BooksOfAll Simplified Chinese<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Blocks in Ruby - BooksOfAll Simplified Chinese\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOfAll Simplified Chinese\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-28T07:07:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png\" \/>\n<meta name=\"twitter:label1\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/\",\"url\":\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/\",\"name\":\"Using Blocks in Ruby - BooksOfAll Simplified Chinese\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/cn\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png\",\"datePublished\":\"2023-02-28T07:07:34+00:00\",\"dateModified\":\"2023-02-28T07:07:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png\",\"width\":\"451\",\"height\":\"682\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/cn\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using Blocks in Ruby\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/cn\/#website\",\"url\":\"https:\/\/www.booksofall.com\/cn\/\",\"name\":\"BooksOfAll Simplified Chinese\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/cn\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/cn\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/cn\/#organization\",\"name\":\"BooksOfAll Simplified Chinese\",\"url\":\"https:\/\/www.booksofall.com\/cn\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.booksofall.com\/cn\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOfAll Simplified Chinese\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/cn\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using Blocks in Ruby - BooksOfAll Simplified Chinese","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/","og_locale":"zh_CN","og_type":"article","og_title":"Using Blocks in Ruby - BooksOfAll Simplified Chinese","og_url":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/","og_site_name":"BooksOfAll Simplified Chinese","article_modified_time":"2023-02-28T07:07:35+00:00","og_image":[{"url":"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png","twitter_misc":{"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/","url":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/","name":"Using Blocks in Ruby - BooksOfAll Simplified Chinese","isPartOf":{"@id":"https:\/\/www.booksofall.com\/cn\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png","datePublished":"2023-02-28T07:07:34+00:00","dateModified":"2023-02-28T07:07:35+00:00","breadcrumb":{"@id":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#primaryimage","url":"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png","contentUrl":"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2023\/02\/img_63fda6022fb77.png","width":"451","height":"682"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/cn\/using-blocks-in-ruby\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/cn\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/cn\/categories\/"},{"@type":"ListItem","position":3,"name":"Using Blocks in Ruby"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/cn\/#website","url":"https:\/\/www.booksofall.com\/cn\/","name":"BooksOfAll Simplified Chinese","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/cn\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/cn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/cn\/#organization","name":"BooksOfAll Simplified Chinese","url":"https:\/\/www.booksofall.com\/cn\/","logo":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.booksofall.com\/cn\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/cn\/wp-content\/uploads\/sites\/2\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOfAll Simplified Chinese"},"image":{"@id":"https:\/\/www.booksofall.com\/cn\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/cn\/wp-json\/wp\/v2\/product\/22739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/cn\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/cn\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/cn\/wp-json\/wp\/v2\/media\/22743"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/cn\/wp-json\/wp\/v2\/media?parent=22739"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/cn\/wp-json\/wp\/v2\/product_brand?post=22739"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/cn\/wp-json\/wp\/v2\/product_cat?post=22739"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/cn\/wp-json\/wp\/v2\/product_tag?post=22739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}