From ac15f60161fda79685fcf9ae7d203be8e38b32b8 Mon Sep 17 00:00:00 2001
From: Michael Aaron Murphy <mmstickman@gmail.com>
Date: Fri, 28 Jul 2017 17:22:05 -0400
Subject: [PATCH] Remove @len() & Migrate Logic Into $len()

---
 examples/methods.ion             |  4 ++--
 src/parser/shell_expand/words.rs | 21 ++++++++++-----------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/examples/methods.ion b/examples/methods.ion
index 32292ba7..8fe3fe80 100644
--- a/examples/methods.ion
+++ b/examples/methods.ion
@@ -7,8 +7,8 @@ echo @split(space_string)
 echo @split(comma_string, ', ')
 
 let array = ["one two" "three four" "five six" "seven eight" "nine ten"]
-echo @len(array)
-for element in 0..@len(array)
+echo $len(@array)
+for element in 0..$len(@array)
     echo @array[$element]
 end
 
diff --git a/src/parser/shell_expand/words.rs b/src/parser/shell_expand/words.rs
index 0785759c..d925ac33 100644
--- a/src/parser/shell_expand/words.rs
+++ b/src/parser/shell_expand/words.rs
@@ -235,16 +235,6 @@ impl<'a> ArrayMethod<'a> {
 
     pub fn handle(&self, current: &mut String, expand_func: &ExpanderFunctions) {
         match self.method {
-            "len" => {
-                if let Some(array) = expand_func.vars.get_array(self.variable) {
-                    current.push_str(&array.len().to_string())
-                } else if is_expression(self.variable) {
-                    let expanded = expand_string(self.variable, expand_func, false);
-                    current.push_str(&expanded.len().to_string());
-                } else {
-                    current.push_str("0")
-                }
-            },
             "split" => {
                 let variable = if let Some(variable) = (expand_func.variable)(self.variable, false) {
                     variable
@@ -462,7 +452,16 @@ impl<'a> StringMethod<'a> {
                 }
             },
             "len" => {
-                if let Some(value) = expand.vars.get_var(self.variable) {
+                if self.variable.starts_with('@') || self.variable.starts_with('[') {
+                    if let Some(array) = expand.vars.get_array(self.variable) {
+                        output.push_str(&array.len().to_string())
+                    } else if is_expression(self.variable) {
+                        let expanded = expand_string(self.variable, expand, false);
+                        output.push_str(&expanded.len().to_string());
+                    } else {
+                        output.push_str("0")
+                    }
+                } else if let Some(value) = expand.vars.get_var(self.variable) {
                     let count = UnicodeSegmentation::graphemes(value.as_str(), true).count();
                     output.push_str(&count.to_string());
                 } else if is_expression(self.variable) {
-- 
GitLab