{"id":5571,"date":"2015-02-25T03:41:21","date_gmt":"2015-02-25T03:41:21","guid":{"rendered":"https:\/\/testingbaires.com\/?p=5571"},"modified":"2015-05-17T12:38:51","modified_gmt":"2015-05-17T12:38:51","slug":"tutorial-ruby-parte-23-variables","status":"publish","type":"post","link":"https:\/\/testingbaires.com\/tutorial-ruby-parte-23-variables\/","title":{"rendered":"Tutorial de Ruby \u2013 Parte 23 \u2013 Variables"},"content":{"rendered":"<p style=\"text-align: justify;\"><b>Cap\u00edtulo 20. Variables<\/b><\/p>\n<p style=\"text-align: justify;\"><strong><strong>\u00a0<\/strong><\/strong><\/p>\n<p style=\"text-align: justify;\">Ruby tiene tres clases de variables, una clase de constante y exactamente dos pseudo-variables. Las variables y las constantes no tienen tipo. Aunque las variables sin tipo tienen sus inconvenientes, presentan m\u00e1s ventajas y se adaptan mejor a la filosof\u00eda r\u00e1pido y sencillo de Ruby<\/p>\n<p style=\"text-align: justify;\"><strong><strong>\u00a0<\/strong><\/strong><\/p>\n<p style=\"text-align: justify;\">En la mayor\u00eda de los lenguajes hay que declarar las variables para especificar su tipo, si se pueden modificar (e.g. si son constantes) e indicar su \u00e1mbito, ya que no es ning\u00fan problema el tipo y como vamos a ver, el resto se obtiene a partir del nombre, en Ruby no se necesita declarar las variables.<\/p>\n<p style=\"text-align: justify;\"><strong><strong>\u00a0<\/strong><\/strong><\/p>\n<p style=\"text-align: justify;\">El primer car\u00e1cter de un identificador lo cataloga de un plumazo:<\/p>\n<p style=\"text-align: justify;\"><strong><strong>\u00a0<\/strong><\/strong><\/p>\n<p style=\"text-align: justify;\">Tabla 20-1. Clases de variables<\/p>\n<p style=\"text-align: justify;\"><strong><strong><\/p>\n<p><\/strong><\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td>$<\/td>\n<td>Variable global<\/td>\n<\/tr>\n<tr>\n<td>@<\/td>\n<td>Variable instancia<\/td>\n<\/tr>\n<tr>\n<td>[a-z] \u00f3 _<\/td>\n<td>Variable local<\/td>\n<\/tr>\n<tr>\n<td>[A-Z]<\/td>\n<td>Constante<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: justify;\"><strong><strong>\u00a0<\/strong><\/strong><\/p>\n<p style=\"text-align: justify;\">Las \u00fanicas excepciones a lo expuesto en la tabla son las pseudo-variables de Ruby: self, que referencia al objeto que est\u00e1 en ese momento en ejecuci\u00f3n y nil que es el valor nulo que toman las variables no inicializadas. Ambos tienen un identificador como de variable local pero self es una variable global que la mantiene el interprete y nil es una constante. Como estas son las \u00fanicas excepciones no provocan mucha confusi\u00f3n.<\/p>\n<p style=\"text-align: justify;\"><strong><strong>\u00a0<\/strong><\/strong><\/p>\n<p style=\"text-align: justify;\">No se debe asignar valores a self y nil principalmente porque un valor de self referencia al objeto de nivel superior:<\/p>\n<p style=\"text-align: justify;\"><strong><strong>\u00a0<\/strong><\/strong><\/p>\n<p style=\"text-align: justify;\">ruby&gt; self<\/p>\n<p style=\"text-align: justify;\">main<\/p>\n<p style=\"text-align: justify;\">ruby&gt; nil<\/p>\n<p style=\"text-align: justify;\">nil<\/p>\n<p style=\"text-align: justify;\"><strong><\/p>\n<p><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cap\u00edtulo 20. Variables \u00a0 Ruby tiene tres clases de variables, una clase de constante y exactamente dos pseudo-variables. Las variables y las constantes no tienen tipo. Aunque las variables sin tipo tienen sus inconvenientes, presentan m\u00e1s ventajas y se adaptan mejor a la filosof\u00eda r\u00e1pido y sencillo de Ruby \u00a0 En la mayor\u00eda de los [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[86,74,760,2],"tags":[1029,860,494,999,793],"class_list":["post-5571","post","type-post","status-publish","format-standard","hentry","category-automatizacion","category-capacitacion","category-ruby","category-tutorial","tag-automatizacion","tag-automatizacion-de-pruebas","tag-ruby","tag-tutorial","tag-variables","entry"],"_links":{"self":[{"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/posts\/5571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/comments?post=5571"}],"version-history":[{"count":2,"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/posts\/5571\/revisions"}],"predecessor-version":[{"id":6382,"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/posts\/5571\/revisions\/6382"}],"wp:attachment":[{"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/media?parent=5571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/categories?post=5571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/testingbaires.com\/wp-json\/wp\/v2\/tags?post=5571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}